https://programmers.co.kr/learn/courses/30/lessons/12932
자연수 n을 뒤집어 각 자리 숫자를 원소로 가지는 배열 형태로 리턴해주세요.
예를들어 n이 12345이면 [5,4,3,2,1]을 리턴합니다.
자바에서 숫자의 자리수를 구할때는 String으로 변환해서 해도 가능하지만, 수학적으로 로그 10의 +1을 하면 자리수를 구할 수 있다.
class Solution {
public static int[] solution(long n) {
int[] answer = new int[(int) Math.log10(n) + 1];
int reverse = 0;
for (int i = 0; n != 0; i++) {
answer[i] = (int) (n % 10);
n /= 10;
}
return answer;
}
}
def solution(n):
lis = list(map(int, str(n)))
lis.reverse()
return lis