프로그래머스 java 음양 더하기

jieun·2022년 8월 15일
0

java 코테 공부

목록 보기
7/17

해결방법

  1. sings이 참이면 그대로 더하고 거짓이면 -붙여서 더함

전체코드

class Solution {
    public int solution(int[] absolutes, boolean[] signs) {
        int answer = 0;
        for (int i=0; i<signs.length; i++) 
            answer += signs[i] ? absolutes[i] : -absolutes[i];
        return answer;
    }
}
profile
개발새발 블로그

0개의 댓글