-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_681.java
34 lines (31 loc) · 1.06 KB
/
_681.java
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
31
32
33
34
package com.fishercoder.solutions.firstthousand;
import java.util.HashSet;
import java.util.Set;
public class _681 {
public static class Solution1 {
public String nextClosestTime(String time) {
int cur = 60 * Integer.parseInt(time.substring(0, 2));
cur += Integer.parseInt(time.substring(3));
Set<Integer> allowed = new HashSet();
for (char c : time.toCharArray()) {
if (c != ':') {
allowed.add(c - '0');
}
}
while (true) {
cur = (cur + 1) % (24 * 60);
int[] digits =
new int[] {cur / 60 / 10, cur / 60 % 10, cur % 60 / 10, cur % 60 % 10};
search:
{
for (int d : digits) {
if (!allowed.contains(d)) {
break search;
}
}
return String.format("%02d:%02d", cur / 60, cur % 60);
}
}
}
}
}