ALGORITHM 🤖/Programmers

프로그래머스 - 배열 뒤집기

daxx0ne 2023. 2. 27. 16:01

https://school.programmers.co.kr/learn/courses/30/lessons/120821

class Solution {
    public int[] solution(int[] num_list) {
        
	//num_list의 길이만큼 answer 배열의 크기를 지정
        int[] answer = new int[num_list.length]; 
        
        for(int i = 0; i < num_list.length; i++){ //0부터 num_list의 길이만큼 반복
            answer[i] = num_list[num_list.length - i -1]; 

        return answer; //answer을 리턴하면 num_list 배열이 뒤집어져서 나옴!
    }
}