[문제링크 - 프로그래머스 - 조건에 맞게 수열 변환하기 3] https://school.programmers.co.kr/learn/courses/30/lessons/181835#
class Solution {
public int[] solution(int[] arr, int k) {
int[] answer = new int[arr.length];
if(k % 2 != 0) {
for(int i=0; i<arr.length; i++){
answer[i] = arr[i] * k;
}
} else {
for(int i=0; i<arr.length; i++){
answer[i] = arr[i] + k;
}
}
return answer;
}
}
import java.util.stream.IntStream;
class Solution {
public int[] solution(int[] arr, int k) {
if(k%2==0) {
return IntStream.of(arr).map(i->i+k).toArray();
}
return IntStream.of(arr).map(i->i*k).toArray();
}
}
내 풀이
다른 사람 풀이