[알고리즘문제풀기] 등차수열의 특정한 항만 더하기

silver's avatar
Sep 07, 2025
[알고리즘문제풀기] 등차수열의 특정한 항만 더하기

문제

내가 작성한 정답

class Solution { public int solution(int a, int d, boolean[] included) { int answer = 0; for(int i=0; i<included.length; i++){ answer += (included[i])? (a+d*i):0; } return answer; } }

다른 사람들의 정답

import java.util.stream.IntStream; class Solution { public int solution(int a, int d, boolean[] included) { return IntStream.range(0, included.length).map(idx -> included[idx]?a+(idx*d):0).sum(); } }
Share article

silver