Skip to content

Commit c6c05bc

Browse files
committed
Time: 2 ms (80.64%), Space: 41.1 MB (52.85%) - LeetHub
1 parent aef47f6 commit c6c05bc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution
2+
{
3+
public String largestGoodInteger(String num)
4+
{
5+
String ans = "";
6+
for(int i = 2; i < num.length(); i++)
7+
if(num.charAt(i) == num.charAt(i-1) && num.charAt(i-1) == num.charAt(i-2))
8+
if(num.substring(i-2,i+1).compareTo(ans) > 0) // Check if the new one is larger
9+
ans = num.substring(i-2,i+1);
10+
return ans;
11+
}
12+
}

0 commit comments

Comments
 (0)