풀이과정
signs이 참이면 더해주면 되고, 거짓이면 빼주면 된다.
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> absolutes, vector<bool> signs) {
int answer = 0;
for(int i = 0; i < absolutes.size(); i++){
if(signs[i]) answer += absolutes[i];
else answer -= absolutes[i];
}
return answer;
}
'🍞 Problem Solving > Programmers' 카테고리의 다른 글
[프로그래머스][Level1] 문자열 내 마음대로 정렬하기 c++ (0) | 2022.09.03 |
---|---|
[프로그래머스][Level1] 2016년 c++ (0) | 2022.09.03 |
[프로그래머스][Level1] 완주하지 못한 선수 c++ (0) | 2022.09.03 |
[프로그래머스][Level1] 예산 c++ (0) | 2022.09.03 |
[프로그래머스][Level1] 없는 숫자 더하기 c++ (0) | 2022.09.03 |