본문 바로가기
코딩테스트/프로그래머스 Lv.0

[코테/0레벨] 배열 뒤집기

by moca7 2025. 1. 31.

 

 

 

 

ㅁ 내 풀이

 

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

 

 

ㅁ 다른 풀이

 

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-i-1];
        }
        return answer;
    }
}

 

- 후위 증감연산자 대신 1씩 증가하는 i를 사용한 풀이.