자연수 n을 뒤집어 각 자리 숫자를 원소로 가지는 배열 형태로 리턴해주세요. 예를들어 n이 12345이면 [5,4,3,2,1]을 리턴합니다.
class Solution {
public int[] solution(long n) {
String nStr = String.valueOf(n);
int[] answer = new int[nStr.length()];
int idx = 0;
for(int i=nStr.length() - 1; i>=0; i--){
answer[idx++] = Integer.parseInt(String.valueOf(nStr.charAt(i)));
}
return answer;
}
}
