프로그래머스 문자열 나누기 - java


프로그래머스 문자열 나누기 - java

독해력 문제였다. class Solution { public int solution(String s) { int answer = 0; char x = ' '; int countX = 0; int countOthers = 0; for (int i = 0 ; i < s.length() ; i++) { if (s.length() == 1) { answer++; break; }//if if (i == 0) { //먼저 첫 글자를 읽습니다. 이 글자를 x라고 합시다. countOthers = 0; countX++; x = s.charAt(i); }//if else { // x와 x가 아닌 다른 글자들이 나온 횟수를 각각 셉니다. if (s.charAt(i) == x) { countX++; }//if else { countOthers++; if (countX == countOthers) { // 처음으로 두 횟수가 같아지는 순간 멈추고, 지금까지 읽은 문자열을 분리합니다. s = s.subst...



원문링크 : 프로그래머스 문자열 나누기 - java