개발일지

자바_배열 뒤집기_Programmers 본문

코딩테스트

자바_배열 뒤집기_Programmers

딸기아사이레모네이드리프레셔 2023. 3. 16. 13:46
728x90

문제

정수가 들어 있는 배열 num_list가 매개변수로 주어집니다. num_list의 원소의 순서를 거꾸로 뒤집은 배열을 return하도록 solution 함수를 완성해주세요.

 

본인 풀이

class Solution {
    public int[] solution(int[] num_list) {
    
        int[] answer = new int[num_list.length];
        
        for(int i=0;i<num_list.length;i++){
             answer[i] = num_list[num_list.length - 1 - i];
        }
        return answer;
    }
}
728x90
Comments