
나의 풀이
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] * 1 ;
} else {
answer += absolutes[i] * -1 ;
}
}
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) | 2024.11.12 |
|---|---|
| [프로그래머스] 핸드폰 번호 가리기(Java) (0) | 2024.11.11 |
| [프로그래머스] 나누어 떨어지는 숫자 배열 (1) | 2024.11.09 |
| [프로그래머스] 서울에서 김서방 찾기(Java) (0) | 2024.11.08 |
| [프로그래머스] 콜라츠 추측(Java) * (0) | 2024.11.07 |