https://leetcode.com/problems/consecutive-characters/description/
Consecutive Characters - LeetCode
Consecutive Characters - The power of the string is the maximum length of a non-empty substring that contains only one unique character. Given a string s, return the power of s. Example 1: Input: s = "leetcode" Output: 2 Explanation: The substring "ee"
leetcode.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
class Solution:
def maxPower(self, s: str) -> int:
answer = 1
tmp_cnt = 1
ex_chr = ''
for current_chr in s:
if ex_chr==current_chr:
tmp_cnt+=1
else:
tmp_cnt = 1
answer = max(tmp_cnt,answer)
ex_chr = current_chr
return answer
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 231. Power of Two (0) | 2023.01.17 |
---|---|
백준 27219 Робинзон Крузо (0) | 2023.01.16 |
leetcode 2042. Check if Numbers Are Ascending in a Sentence (0) | 2023.01.13 |
leetcode 191. Number of 1 Bits (0) | 2023.01.13 |
leetcode 2138. Divide a String Into Groups of Size k (0) | 2023.01.12 |
댓글