첫 풀이 [비효율적]
class Solution {
public String solution(int n, int t, int m, int p) {
String answer = "";
int mySaveNumCount = 0;
int number = 0;
String numberString = "0";
int numCount = 0;
int turnCount = 1;
while(mySaveNumCount != t){
if(numCount == numberString.length()){
number++;
numberString = Integer.toString(number, n);
numCount = 0;
}
if(turnCount == p){
answer += numberString.charAt(numCount);
mySaveNumCount++;
}
if(turnCount < m){
turnCount++;
}else{
turnCount = 1;
}
numCount++;
}
return answer.toUpperCase();
}
}
두번째 풀이 [시간 단축]
class Solution {
public String solution(int n, int t, int m, int p) {
StringBuilder answer = new StringBuilder();
int number = 0;
StringBuilder allNumberString = new StringBuilder();
while (allNumberString.length() < t * m){
allNumberString.append(Integer.toString(number, n));
number++;
}
for (int round = 0; round < t; round++) {
answer.append(allNumberString.charAt(p - 1 + (round * m)));
}
return answer.toString().toUpperCase();
}
}