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

업데이트:

📚 음양 더하기

난이도 ⭐️

📖 문제

이미지 이미지

📝 내 풀이

#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;
}

앞선 풀이에서 말했듯 콜렉션 프레임워크의 경우 크기를 알고자 할 때 .size( )를 사용한다.

댓글남기기