99클럽 코테 스터디 3일차 TIL + 문자열
2024. 10. 30. 16:46ㆍAlgorithm Problem Solving
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
1. 알고리즘! 생각해보자
반복문에서
1) 글자수 카운트 비교
2) 글자 비교
2. 해결 코드
class Solution {
public int solution(String s) {
int answer = 0;
char first = s.charAt(0);
int firstCount = 0;
int otherCount = 0;
for(int i=0; i<s.length(); i++) {
if(firstCount == otherCount) {
first = s.charAt(i);
answer++;
}
if(first == s.charAt(i)) {
firstCount++;
} else {
otherCount++;
}
}
return answer;
}
}
3. 레퍼런스
[프로그래머스] 문자열 나누기(Java)
구현
velog.io
'Algorithm Problem Solving' 카테고리의 다른 글
99클럽 코테 스터디 5일차 TIL + 해시 (0) | 2024.11.01 |
---|---|
99클럽 코테 스터디 4일차 TIL + 문자열 (0) | 2024.10.31 |
99클럽 코테 스터디 2일차 TIL + 문자열 (1) | 2024.10.29 |
99클럽 코테 스터디 1일차 TIL + 문자열 (1) | 2024.10.28 |
Lv2. 전력망을 둘로 나누기 (0) | 2021.11.20 |