-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2264.cpp
More file actions
26 lines (26 loc) · 684 Bytes
/
2264.cpp
File metadata and controls
26 lines (26 loc) · 684 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
class Solution {
public:
string largestGoodInteger(string num) {
int resVal = -1;
int index = 0;
int n = num.size();
while (index < n) {
char curr = num[index];
int start = index;
while (index + 1 < n && num[index + 1] == curr) {
index++;
}
int length = index - start + 1;
if (length >= 3) {
if (curr > resVal) {
resVal = curr;
}
}
index++;
}
if (resVal == -1) return "";
char c = (char)(resVal);
string res = string(3, c);
return res;
}
};