내 답안
class Solution {
public int solution(int a, int d, boolean[] included) {
int answer = 0;
for(int i=0; i<included.length; i++){
if(included[i]){
answer += a+(d*i);
}
}
return answer;
}
}
Java
복사
다른 사람 풀이법
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();
}
}
Java
복사
class Solution {
public int solution(int a, int d, boolean[] included) {
int answer = 0;
for (int i = 0; i < included.length; i++) {
if (included[i]) {
answer += a;
}
a += d;
}
return answer;
}
}
Java
복사