๋ฌธ์
์ฝ๋
#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])+1;
}
return answer;
}
ํ์ด(1๋ถ 50์ด)
O(N)์ผ๋ก signs์ด true์ผ ๊ฒฝ์ฐ ๋ํด์ฃผ๊ณ signs๊ฐ false์ผ ๊ฒฝ์ฐ 2์ ๋ณด์ ํํ๋ก ๋ฐ๊ฟ ์์๋ก ๋ง๋ ํ ๋ํด์ฃผ์์ต๋๋ค.
๋๊ธ