Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 에러
- GitHub
- 시큐리티
- Eclipse
- 코틀린
- mybatis
- Security
- 쿼리
- db
- Vue
- 생성
- 함수
- 넥사크로
- 스프링
- JavaScript
- 오라클
- jquery
- Spring
- JPA
- kotlin
- IntelliJ
- 프로그래머스
- 자바
- oracle
- aws
- error
- 방법
- Java
- Git
- 알고리즘
Archives
- Today
- Total
송민준의 개발노트
[프로그래머스] 없는 숫자 더하기 본문
https://programmers.co.kr/learn/courses/30/lessons/86051?language=java
코딩테스트 연습 - 없는 숫자 더하기
0부터 9까지의 숫자 중 일부가 들어있는 정수 배열 numbers가 매개변수로 주어집니다. numbers에서 찾을 수 없는 0부터 9까지의 숫자를 모두 찾아 더한 수를 return 하도록 solution 함수를 완성해주세요.
programmers.co.kr
주어진 숫자를 배열의 인덱스로 취급하고 해당 값을 1씩 증가시켰다.
class Solution {
public int solution(int[] numbers) {
int answer = 0;
int[] counts = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
for(int number : numbers) {
counts[number]++;
}
for(int i = 0; i < counts.length; i++) {
if(counts[i] == 0) answer += i;
}
return answer;
}
}
참고할만한 풀이
class Solution {
public int solution(int[] numbers) {
int sum = 45;
for (int i : numbers) {
sum -= i;
}
return sum;
}
}
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 더 맵게 (0) | 2022.04.25 |
---|---|
[프로그래머스] 음양 더하기 (0) | 2022.04.24 |
[프로그래머스] 키패드 누르기 (0) | 2022.04.18 |
[프로그래머스] 숫자 문자열과 영단어 (0) | 2022.04.10 |
[프로그래머스] 신규 아이디 추천 (0) | 2022.04.03 |