Skip to content

Commit 58bdfd2

Browse files
refactor 1437
1 parent 51fd552 commit 58bdfd2

File tree

2 files changed

+66
-11
lines changed

2 files changed

+66
-11
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.fishercoder.solutions;
2+
3+
public class Contest {
4+
5+
public String maximumTime(String time) {
6+
StringBuilder sb = new StringBuilder();
7+
String[] strs = time.split(":");
8+
String hour = strs[0];
9+
String min = strs[1];
10+
if (hour.charAt(0) == '?') {
11+
if (hour.charAt(1) == '?') {
12+
sb.append("23");
13+
} else if (hour.charAt(1) > '3') {
14+
sb.append("1");
15+
sb.append(hour.charAt(1));
16+
} else {
17+
sb.append("2");
18+
sb.append(hour.charAt(1));
19+
}
20+
} else if (hour.charAt(0) == '0' || hour.charAt(0) == '1') {
21+
if (hour.charAt(1) == '?') {
22+
sb.append(hour.charAt(0));
23+
sb.append("9");
24+
} else {
25+
sb.append(hour);
26+
}
27+
} else if (hour.charAt(0) == '2') {
28+
if (hour.charAt(1) == '?') {
29+
sb.append("23");
30+
} else {
31+
sb.append(hour);
32+
}
33+
}
34+
sb.append(":");
35+
if (min.charAt(0) == '?') {
36+
if (min.charAt(1) == '?') {
37+
sb.append("59");
38+
} else {
39+
sb.append("5");
40+
sb.append(min.charAt(1));
41+
}
42+
return sb.toString();
43+
}
44+
sb.append(min.charAt(0));
45+
if (min.charAt(1) == '?') {
46+
sb.append("9");
47+
} else {
48+
sb.append(min.charAt(1));
49+
}
50+
return sb.toString();
51+
}
52+
53+
public static void main(String... args) {
54+
Contest contest = new Contest();
55+
System.out.println("Hello world!");
56+
System.out.println(contest.maximumTime("?0:15"));
57+
System.out.println("Finished!");
58+
}
59+
}

src/main/java/com/fishercoder/solutions/_1437.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
package com.fishercoder.solutions;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
63
public class _1437 {
74
public static class Solution1 {
85
public boolean kLengthApart(int[] nums, int k) {
9-
List<Integer> indexes = new ArrayList<>();
10-
for (int i = 0; i < nums.length; i++) {
6+
int lastOneIndex = nums[0] == 1 ? 0 : -1;
7+
for (int i = 1; i < nums.length; i++) {
118
if (nums[i] == 1) {
12-
indexes.add(i);
13-
}
14-
}
15-
for (int i = 0; i < indexes.size() - 1; i++) {
16-
if (indexes.get(i + 1) - indexes.get(i) < k + 1) {
17-
return false;
9+
if (i - lastOneIndex <= k) {
10+
return false;
11+
} else {
12+
lastOneIndex = i;
13+
}
1814
}
1915
}
2016
return true;

0 commit comments

Comments
 (0)