Written by
java-style
on
on
[JAVA] 프로그래머스 음양 더하기
[JAVA] 프로그래머스 음양 더하기
728x90
알고리즘
JAVA 프로그래머스 음양 더하기
1. 문제
https://programmers.co.kr/learn/courses/30/lessons/76501
2. 풀이
signs가 true일 때 값을 더하고, 그렇지 않을 때 마이너스
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; } }
728x90
from http://yuricoding.tistory.com/39 by ccl(A) rewrite - 2021-11-08 16:01:29