코딩 테스트/프로그래머스

프로그래머스 | 자연수 뒤집어 배열로 만들기

한 면만 쓴 종이 2022. 7. 15. 17:22
public class Solution {
	public static int[] solution(long n) {
		int t = 0;
		long k = n;

		while(n > 0) {
			t++;
			n /= 10;
		}
		int[] answer = new int[t];
		for (int i = 0; i < t; i++) {
			answer[i] = (int)(k%10);
			k /= 10;
		}
		return answer;
	}
}