
나의 풀이
class Solution {
public int solution(int[] a, int[] b) {
int answer = 0;
for(int i=0; i < a.length; i++){
answer += a[i] * b[i];
}
return answer;
}
}
다른 사람의 풀이
import java.util.stream.IntStream;
class Solution {
public int solution(int[] a, int[] b) {
return IntStream.range(0, a.length).map(index -> a[index] * b[index]).sum();
}
}'알고리즘' 카테고리의 다른 글
| [프로그래머스] 문자열 내림차순으로 배치하기(Java) (0) | 2024.11.18 |
|---|---|
| [프로그래머스] 약수의 개수와 덧셈(Java) (0) | 2024.11.17 |
| [프로그래머스] 수박수박수박수박수박수?(Java) (0) | 2024.11.15 |
| [프로그래머스] 가운데 글자 가져오기(Java) (0) | 2024.11.14 |
| [프로그래머스] 제일 작은 수 제거하기(Java) * (0) | 2024.11.13 |