문제 설명

솔루션
class Solution {
public int solution(int[] absolutes, boolean[] signs) {
int answer = 0;
for(int i = 0; i < signs.length; i++){
if(signs[i]){
answer += absolutes[i];
}else{
answer -= absolutes[i];
}
}
return answer;
}
}
다른 풀이
class Solution {
public int solution(int[] absolutes, boolean[] signs) {
int answer = 0;
for (int i=0; i<signs.length; i++)
answer += absolutes[i] * (signs[i]? 1: -1);
return answer;
}
}'java' 카테고리의 다른 글
| [프로그래머스 - 자바] 없는 숫자 더하기 (0) | 2023.09.19 |
|---|---|
| [프로그래머스 - 자바] 핸드폰 번호 가리기 (0) | 2023.09.19 |
| [프로그래머스 - 자바] 나누어 떨어지는 숫자 배열 (0) | 2023.09.19 |
| [프로그래머스 - 자바] 콜라츠 추측 (0) | 2023.09.19 |
| [프로그래머스 - 자바] 두 정수사이의 합 (0) | 2023.09.19 |