Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- DP
- SWEA
- db
- SQL
- 프로그래머스
- COS PRO
- 이분탐색
- dfs
- 문제풀이
- 건강
- 운동기록
- BFS
- 코딩테스트
- BOJ
- binary search
- 코테
- 시뮬레이션
- 알고리즘
- Java
- 투포인터
- 문자열
- 자바
- greedy
- 러닝일지
- MySQL
- 문제해결
- math
- oracle
- 백준
- priorityqueue
Archives
- Today
- Total
슈콩
COS PRO 1급 JAVA 자아도취 수 본문


[소스 코드]
import java.util.Arrays;
class Main {
public int power(int base, int exponent) {
int val = 1;
for (int i = 0; i < exponent; i++)
val *= base;
return val;
}
public int[] solution(int k) {
int range = power(10, k);
int[] answer = new int[range];
int count = 0;
for (int i = range / 10; i < range; i++) {
int current = i;
int calculated = 0;
while (current != 0) {
calculated += power(current%10,k);
current /= 10;
}
if (calculated == i)
answer[count++] = i;
}
int[] ret = new int[count];
for (int i = 0; i < count; i++)
ret[i] = answer[i];
return ret;
}
}