본문 바로가기

Algorithm

프로그래머스 - 배열 두 배 만들기

문제 : 정수 배열 numbers가 매개변수로 주어집니다. numbers의 각 원소에 두배한 원소를 가진 배열을 return하도록 solution 함수를 완성해주세요.

 

풀이 : 

class Solution {
    public int[] solution(int[] numbers) {
        int len = numbers.length;
        int[] answer = new int[len];
                
        for(int i=0; i<len; i++){
            answer[i] = numbers[i]*2;
        }
       
        return answer;
    }
}