https://school.programmers.co.kr/learn/courses/30/lessons/12932

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr


하나씩 나누어 가면서 진행한다.

자바의 경우 배열의 크기가 한 번 정해지면 바꿀 수 없기 때문에

ArrayList를 이용해볼까... 했지만 귀찮아서

String으로 바꾸어 length로 자릿수를 계산했다.

루비는 배열에 append가 가능하기 때문에 간단.

 

 

 

- Java

class Solution {
    public int[] solution(long d) {
        int a = String.valueOf(d).length();
		int[] answer = new int[a];
		
		for(int i=0;i<a;i++) {
			answer[i]=(int) (d%10);
			d/=10;
		}
		
		
        return answer;
    }
}

 

 

- Ruby

def solution(n)
    answer = []
    while n>0
        answer.append(n%10)
        n=n/10
    end
    return answer
end

 

+ Recent posts