[Java 알고리즘 문제] (14) 배열 뒤집기

KangHo Lee's avatar
Nov 24, 2024
[Java 알고리즘 문제] (14) 배열 뒤집기

문제 설명

정수가 들어 있는 배열 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, j = num_list.length - 1; i < answer.length; i++, j--) { answer[i] = num_list[j]; } return answer; } }
 
Share article

devleekangho