1446. 连续字符

题目链接:https://leetcode.cn/problems/consecutive-characters/description/

Java

执行用时分布1ms 击败100.00%使用 Java 的用户
消耗内存分布41.40MB 击败49.68%使用 Java 的用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public int maxPower(String s) {
int n = s.length();
if (n == 1) return 1;
int res = 0;
for (int i = 0; i < n - 1; i++) {
int start = i;
char x = s.charAt(i);
while (i < n - 1 && x == s.charAt(i + 1)) {
i++;
}
res = Math.max(res, i-start+1);
}

return res;
}
}

1446. 连续字符
https://pisces34.github.io/2025/03/14/leetcode/1446/
发布于
2025年3月14日
许可协议