[알고리즘문제풀기]배열 뒤집기

프로그래머스 입문 문제
송송승현's avatar
Dec 26, 2024
[알고리즘문제풀기]배열 뒤집기

문제

나의 해답

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

해설

  • num_list와 길이가 같은 배열 answer을 생성 초기화
  • 반복문을 사용하여 num_list를 끝에서부터 불러와서 answer의 첫번째 부터 쌓기
Share article

송승현의 블로그