문제 설명
정수가 들어 있는 배열 num_list가 매개변수로 주어집니다. num_list의 원소의 순서를 거꾸로 뒤집은 배열을 return 하도록 solution 함수를 완성해주세요.
<<제안사항>>
1) 1 <= num_list 의 길이 <= 1,000
2) 0 <= num_list의 원소 <= 1,000
내가 직접 짠 코드
class Solution {
public int[] solution(int[] num_list) {
int[] answer = new int [num_list.length];
for(int i=num_list.length; i>=1; i--){
answer[num_list.length-i]=num_list[i-1];
}
return answer;
}
}
코드 설명
1) num_list.length 부터 1까지 돌리며
2) answer [num_list.length-i] 에 num_list[i-1]을 넣어줬습니다!!
'CodingTest' 카테고리의 다른 글
프로그래머스 - 배열 원소의 길이 (JAVA) (0) | 2023.02.17 |
---|---|
프로그래머스 - 짝수 홀수 개수 (JAVA) (0) | 2023.02.16 |
프로그래머스 - 피자 나눠 먹기(1) (JAVA) (0) | 2023.02.15 |
프로그래머스 - 양꼬치 (JAVA) (0) | 2023.02.13 |
프로그래머스 - 배열의 평균값 (JAVA) (0) | 2023.02.13 |