-Code
class Solution {
public int solution(String s) {
int answer = 0;
int same = 0, different = 0;
String now = "";
for (String el : s.split("")) {
if (now.isEmpty()) {
now = el;
}
if (now.equals(el)) same++;
else different++;
if (same == different) {
answer++;
now = "";
same = different = 0;
}
}
return answer + (now.isEmpty() ? 0 : 1);
}
}
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
[프로그래머스/Java] 최솟값 만들기 (0) | 2025.02.28 |
---|---|
[프로그래머스/Java] 최댓값과 최솟값 (0) | 2025.02.27 |
[프로그래머스/Java] 둘만의 암호 (0) | 2025.02.27 |
[프로그래머스/Java] [1차] 다트 게임 (0) | 2025.02.27 |
[프로그래머스/Java] [PCCE 기출문제] 9번 / 지폐 접기 (0) | 2025.02.27 |