99. x사이의 개수

김해준's avatar
Dec 17, 2025
99. x사이의 개수

사용언어 : Java

문제
notion image
풀이
class Solution { public int[] solution(String myString) { int count = 0; for(int i = 0 ; i < myString.length(); i++) { if(myString.charAt(i) == 'x') count++; } System.out.println(count); int[] answer = new int[count + 1]; count = 0; int index = 0; for(int i = 0 ; i < myString.length(); i++) { if(myString.charAt(i) == 'x') { answer[index] = count; count = 0; index++; } else { count++; } } answer[index] = count; return answer; } }
notion image
Share article