https://school.programmers.co.kr/learn/courses/30/lessons/86051
📄 문제
0부터 9까지의 숫자 중 일부가 들어있는 정수 배열 numbers가 매개변수로 주어집니다. numbers에서 찾을 수 없는 0부터 9까지의 숫자를 모두 찾아 더한 수를 return 하도록 solution 함수를 완성해주세요.
📝 풀이
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> numbers) {
int answer = 45;
for(int n : numbers)
answer -= n;
return answer;
}
- 0부터 9까지의 총 합은 45입니다.
- 이 값에서 numbers의 각 값을 빼 answer을 리턴합니다.
'algorithms (C++)' 카테고리의 다른 글
[C++][프로그래머스] 키패드 누르기 (0) | 2023.10.26 |
---|---|
[C++][프로그래머스] 신규 아이디 추천 (0) | 2023.10.25 |
[C++][프로그래머스] 신고 결과 받기 (0) | 2023.10.25 |
[C++][프로그래머스] 성격 유형 검사하기 (1) | 2023.10.24 |
[C++][프로그래머스] 숫자 짝꿍 (0) | 2023.10.23 |