문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
문자열의 power는 하나의 고유 문자만 포함하고 비어 있지 않은 부분 문자열의 최대 길이이다.
문자열 s가 주어졌을 때, s의 power를 반환해라.
#1
Input: s = "leetcode"
Output: 2
Explanation: 부분 문자열 "ee"는 문자 'e'만 가지는 길이 2이다.
#2
Input: s = "abbcccddddeeeeedcba"
Output: 5
Explanation: 부분 문자열 "eeeee"는 문자 'e'만 가지는 길이 5이다.
class Solution {
public int maxPower(String s) {
int result = 1;
int current = 1;
for(int i = 0; i < s.length() - 1; i++){
if(s.charAt(i) == s.charAt(i + 1)){
current++;
result = Math.max(result, current);
}else{
current = 1;
}
}
return result;
}
}