We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a457c11 commit 5bead97Copy full SHA for 5bead97
326. Power of Three 1
@@ -0,0 +1,14 @@
1
+class Solution {
2
+public:
3
+ string largestGoodInteger(string num) {
4
+ string ans = "";
5
+ for (int i = 0; i + 2 < num.size(); i++) {
6
+ // check if current 3 chars are same
7
+ if (num[i] == num[i+1] && num[i] == num[i+2]) {
8
+ string triplet = num.substr(i, 3); // get substring of length 3
9
+ ans = max(ans, triplet); // keep the lexicographically larger one
10
+ }
11
12
+ return ans;
13
14
+};
0 commit comments