문제
내가 작성한 정답
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