forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1736.java
53 lines (52 loc) · 1.72 KB
/
_1736.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.fishercoder.solutions;
public class _1736 {
public static class Solution1 {
public String maximumTime(String time) {
StringBuilder sb = new StringBuilder();
String[] strs = time.split(":");
String hour = strs[0];
String min = strs[1];
if (hour.charAt(0) == '?') {
if (hour.charAt(1) == '?') {
sb.append("23");
} else if (hour.charAt(1) > '3') {
sb.append("1");
sb.append(hour.charAt(1));
} else {
sb.append("2");
sb.append(hour.charAt(1));
}
} else if (hour.charAt(0) == '0' || hour.charAt(0) == '1') {
if (hour.charAt(1) == '?') {
sb.append(hour.charAt(0));
sb.append("9");
} else {
sb.append(hour);
}
} else if (hour.charAt(0) == '2') {
if (hour.charAt(1) == '?') {
sb.append("23");
} else {
sb.append(hour);
}
}
sb.append(":");
if (min.charAt(0) == '?') {
if (min.charAt(1) == '?') {
sb.append("59");
} else {
sb.append("5");
sb.append(min.charAt(1));
}
return sb.toString();
}
sb.append(min.charAt(0));
if (min.charAt(1) == '?') {
sb.append("9");
} else {
sb.append(min.charAt(1));
}
return sb.toString();
}
}
}