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
- 문제풀이
- 알고리즘
- MySQL
- greedy
- BOJ
- SQL
- dfs
- db
- 운동기록
- 건강
- COS PRO
- 프로그래머스
- SWEA
- Java
- 코딩테스트
- 시뮬레이션
- 코테
- priorityqueue
- 자바
- 투포인터
- BFS
- 이분탐색
- 문자열
- oracle
- DP
- binary search
- 러닝일지
- math
- 문제해결
- 백준
Archives
- Today
- Total
슈콩
COS PRO 1급 JAVA 카프리카 수 본문


[소스 코드]
import java.util.*;
class Main {
public int[] solution(int k) {
int[] kaprekarArr = new int[k];
int count = 0;
for (int i = 1; i <= k; i++) {
long squareNum = i * i;
long divisor = 1;
while (squareNum / divisor != 0) {
long front = squareNum / divisor;
long back = squareNum % divisor;
divisor *= 10;
if (back != 0 && front != 0)
if (front + back == i) {
kaprekarArr[count] = i;
count++;
}
}
}
int[] answer = new int[count];
for (int i = 0; i < count; i++)
answer[i] = kaprekarArr[i];
return answer;
}
}