작성
·
215
0
어디가 잘못된 건지 한 번 봐주실 수 있으신가요?
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String next = sc.next();
char c = sc.next().charAt(0);
for(int x : solution(next, c)){
System.out.print(x + " ");
}
}
public static int[] solution(String s, char c){
int[] answer = new int[s.length()];
//오른쪽으로 돌 거
int [] right = new int[s.length()];
//왼쪽으로 돌 거
int[] left = new int[s.length()];
int count = 0;
for(int i =0; i<s.length(); i++){
if(s.charAt(i) != c){
count++;
}else{
count = 0;
}
answer[i] = count;
}
count = 0;
for(int i = s.length()-1; i >=0; i--){
if(s.charAt(i) != c){
count++;
}else{
count = 0;
}
if(count < answer[i]){
answer[i] = count;
}
}
return answer;
}
답변 2