자연수 n을 뒤집어 각 자리 숫자를 원소로 가지는 배열 형태로 리턴해주세요.
예를들어 n이 12345이면 [5,4,3,2,1]을 리턴합니다.
n | return |
---|---|
12345 | [5,4,3,2,1] |
class Solution {
public int[] solution(long n) {
String[] strN = String.valueOf(n).split("");
int[] answer = new int[strN.length];
for (int i = strN.length - 1, j = 0; i >= 0; i--, j++) {
answer[j] = Integer.parseInt(strN[i]);
}
return answer;
}
}
쪼개는거부터 시작해서 배열 뒤짚는 방법은 구글링 참조.
풀이는 생각 나는데 함수가 생각 안나서 발행되는 일들...
정리 중
참고블로그 : https://hianna.tistory.com/515