오늘 배운것
코드카타 problem 7 ~ 17
새싹반 (클래스, 상속)
https://school.programmers.co.kr/learn/courses/30/lessons/12932
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
내 풀이
class Solution {
public int[] solution(long n) {
int size = 0;
long num = n;
while(num!=0){
num = num/10;
size++;
}
int[] answer = new int[size];
for(int i=0; i<size; i++){
answer[i] = (int) (n%10);
n = n/10;
}
return answer;
}
}
조금더 나은 풀이
class Solution {
public int[] solution(long n) {
String a = "" + n;
int[] answer = new int[a.length()];
int cnt=0;
while(n>0) {
answer[cnt]=(int)(n%10);
n/=10;
cnt++;
}
return answer;
}
}
stream을 활용한 신기한 풀이
import java.util.stream.IntStream;
class Solution {
public int[] solution(long n) {
return new StringBuilder().append(n).reverse().chars().map(Character::getNumericValue).toArray();
}
}
git 심화
'스파르타코딩클럽' 카테고리의 다른 글
숫자야구 트러블슈팅 (0) | 2024.10.23 |
---|---|
Day 23 TIL (0) | 2024.10.21 |
계산기 과제 - 트러블 슈팅 (0) | 2024.10.17 |
Day 20 Today I Learned (0) | 2024.10.15 |
Day 19 Today I Learned (0) | 2024.10.14 |