웅재의 코딩세상

[프로그래머스] 음양 더하기 본문

코딩테스트/프로그래머스 - LV 1

[프로그래머스] 음양 더하기

웅드 2024. 2. 9. 17:04

 

  • 풀이
#include <string>
#include <vector>

using namespace std;

int solution(vector<int> absolutes, vector<bool> signs) {
    int answer = 0;
    for(int i=0; i<signs.size(); i++){
        if(signs[i]==false){
            absolutes[i] = (-1)* absolutes[i];
        }
        answer += absolutes[i];
    }
    return answer;
}
반응형