class Solution {
public int solution(int[] absolutes, boolean[] signs) {
int answer = 123456789;
return answer;
}
}
해결법
방법 1
class Solution {
public int solution(int[] absolutes, boolean[] signs) {
int answer = 0;
for (int i = 0; i < absolutes.length; i++) {
if (signs[i]) {
answer += absolutes[i];
} else {
answer -= absolutes[i];
}
}
return answer;
}
}
- signs[i] == true 보단 signs[i]이라고 표기도 무방하다
방법 2
class Solution {
public int solution(int[] absolutes, boolean[] signs) {
int answer = 0;
for(int i = 0; i< absolutes.length; i++){
if (!signs[i]) {
absolutes[i] *= -1;
}
answer += absolutes[i];
}
return answer;
}
}
음양 더하기 Lv. 1