프로그래머스의 없는 숫자 더하기(월간코드챌린지) 문제이다.

 

[ 문제풀이 ]

주어진 배열에서 없는 숫자들을 모두 찾아서 더하면 되는 간단한 문제이다.

본인은 Vector의 find() 함수를 통해서 문제를 접근하였다.

너무 간단한 문제이다 보니, 별도의 설명 보다는 소스코드로 대체하겠다.

 

[ 소스코드 ]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
int solution(vector<int> numbers) 
{
    int answer = 0;
    for(int i = 0 ; i <= 9 ; i++)
    {
        if(find(numbers.begin(), numbers.end(), i) == numbers.end()) answer += i;
    }
    
    return answer;
}
cs

 

 

 

+ Recent posts