forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_2264.java
More file actions
21 lines (20 loc) · 702 Bytes
/
_2264.java
File metadata and controls
21 lines (20 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.fishercoder.solutions;
public class _2264 {
public static class Solution1 {
public String largestGoodInteger(String num) {
String ans = "";
int max = 0;
for (int i = 0; i < num.length() - 2; i++) {
if (num.charAt(i) == num.charAt(i + 1) && num.charAt(i + 1) == num.charAt(i + 2)) {
int candidate = Integer.parseInt(num.substring(i, i + 3));
if (candidate >= max) {
max = candidate;
ans = num.substring(i, i + 3);
}
i += 2;
}
}
return ans;
}
}
}