https://school.programmers.co.kr/learn/courses/30/lessons/140108
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
코드
class Solution {
public static int solution(String s) {
int answer = 0;
StringBuffer sb = new StringBuffer(s);
int i = 1;
int firstCount = 1;
int nextCount = 0;
while(sb.length()>0){
if(i>=sb.length()){
answer++;
break;
}
if(firstCount==nextCount){
sb.delete(0,i);
answer++;
i=1;
firstCount = 1;
nextCount = 0;
continue;
}
else{
if(sb.length()==1){
answer++;
break;
}
if(sb.charAt(0)==sb.charAt(i)){
firstCount++;
}
else{
nextCount++;
}
}
i++;
}
return answer;
}
}
약간은 지저분한 코드인 것 같다..
'알고리즘 > 문제' 카테고리의 다른 글
| [Programmers] 연속 부분 수열 합의 개수 / JAVA -> 실패 (0) | 2023.02.09 |
|---|---|
| [프로그래머스] 과일 장수 / JAVA (0) | 2023.02.06 |
| [프로그래머스] 가장 가까운 같은 글자 | JAVA (0) | 2022.12.18 |
| [프로그래머스] 로또의 최고 순위와 최저 순위 / JAVA (0) | 2022.12.05 |
| <1차도전 실패>[프로그래머스] 신고 결과 받기 / JAVA / 2022 KAKAO BLIND RECRUITMENT (0) | 2022.11.24 |