package ch.programmers;
public class Algorithm6 {
/*
프로그래머스
코딩테스트 연습
월간 코드 챌린지 시즌3
없는 숫자 더하기
*/
class Solution {
public int solution(int[] numbers) {
int answer = 0;
int cnt;
for(int i= 0 ; i < 10; i ++){
cnt = 0;
for(int j = 0; j < numbers.length; j ++){
if(numbers[j] == i){
cnt++;
}
}
if(cnt == 0){
answer += i;
}
}
return answer;
}
}
}
풀이
0 ~ 9의 숫자가 주어졌을때 없는 숫자를 구하는 것이므로 i를 0부터 비교하여 numbers의 숫자들과 비교
만약 numbers에 값이 없다면 answer에 없는 값을 추가하며 해결
'Algorithm > 프로그래머스' 카테고리의 다른 글
프로그래머스 스킬 체크 테스트 (0) | 2022.08.13 |
---|---|
프로그래머스 스킬 체크 테스트 (0) | 2022.08.13 |
프로그래머스 숫자 문자열과 영단어 (0) | 2022.08.10 |
프로그래머스 로또 최고 순위와 최저 순위 (0) | 2022.08.09 |
프로그래머스 소수만들기 (0) | 2022.08.08 |