https://school.programmers.co.kr/learn/courses/30/lessons/76501
소스코드
public class Solution {
public int solution(int[] absolutes, boolean[] signs) {
int answer = 0;
for (int i = 0; i < absolutes.length; i++) {
if(signs[i] == true) {
// 배열의 정수들을 하나씩 더한다.
answer += absolutes[i];
}else {
// 부호가 - 라면 정수를 뺀다.
answer -= absolutes[i];
}
}
return answer;
}
}
반응형
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스 JAVA] 문자열 내림차순으로 배치하기 (0) | 2023.01.06 |
---|---|
[프로그래머스 JAVA] 부족한 금액 계산하기 (0) | 2023.01.04 |
[프로그래머스 JAVA] 문자열 내 p와 y의 개수 (0) | 2023.01.02 |
[프로그래머스 JAVA] K번째수 (0) | 2021.11.30 |
[프로그래머스 JAVA] 완주하지 못한 선수 (0) | 2021.11.28 |