Published:
Updated:


Solution

class Solution {
    public static 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 { // false
                answer -= absolutes[i];
            }
        }
        return answer;
    }

    public static void main(String[] args) {
        System.out.println(solution(new int[]{4, 7, 12}, new boolean[]{true, false, true}));
        System.out.println(solution(new int[]{1, 2, 3}, new boolean[]{false, false, true}));
        System.out.print(solution(new int[]{3, 3, 3, 3}, new boolean[]{false, true, false, true}));
    }
}

Leave a comment