자연수 뒤집어 배열로 만들기

han.user();·2023년 4월 12일
0

프로그래머스

목록 보기
62/87
post-thumbnail

class Solution {
    public int[] solution(long n) {
        String str = Long.toString(n);
        int[] answer = new int[str.length()];

        for (int i = 0; i < str.length(); i++) {
            int c = str.charAt(i) - '0';
            answer[str.length() - i - 1] = c;
        }

        return answer;
    }
}

int 또는 long -> String 바꾼 후 반복문

profile
I'm still hungry.

0개의 댓글