forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
30 lines (30 loc) · 772 Bytes
/
solution.cpp
File metadata and controls
30 lines (30 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution
{
public:
int characterReplacement(string s, int k)
{
int len = s.length();
int maxlen = 0,tl=0;//tl是tmp_len,当前字符的最长重复值
for (int i = 0; i < len; ++i)
{
if (i > 0 && s[i] == s[i-1])
continue;
char cur_letter = s[i];
int count = k;
int j;
for (j = i+1; j < len; ++j)
{
if (s[j] != cur_letter)
count--;
if (count < 0)
break;
}
if(j==len&&count>0)
tl=j-i+min(count,i);
else
tl=j-i;
maxlen = max(maxlen, tl);
}
return maxlen;
}
};