Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit58bdfd2

Browse files
refactor 1437
1 parent51fd552 commit58bdfd2

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+
packagecom.fishercoder.solutions;
2+
3+
publicclassContest {
4+
5+
publicStringmaximumTime(Stringtime) {
6+
StringBuildersb =newStringBuilder();
7+
String[]strs =time.split(":");
8+
Stringhour =strs[0];
9+
Stringmin =strs[1];
10+
if (hour.charAt(0) =='?') {
11+
if (hour.charAt(1) =='?') {
12+
sb.append("23");
13+
}elseif (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+
}elseif (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+
}elseif (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+
returnsb.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+
returnsb.toString();
51+
}
52+
53+
publicstaticvoidmain(String...args) {
54+
Contestcontest =newContest();
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
packagecom.fishercoder.solutions;
22

3-
importjava.util.ArrayList;
4-
importjava.util.List;
5-
63
publicclass_1437 {
74
publicstaticclassSolution1 {
85
publicbooleankLengthApart(int[]nums,intk) {
9-
List<Integer>indexes =newArrayList<>();
10-
for (inti =0;i <nums.length;i++) {
6+
intlastOneIndex =nums[0] ==1 ?0 : -1;
7+
for (inti =1;i <nums.length;i++) {
118
if (nums[i] ==1) {
12-
indexes.add(i);
13-
}
14-
}
15-
for (inti =0;i <indexes.size() -1;i++) {
16-
if (indexes.get(i +1) -indexes.get(i) <k +1) {
17-
returnfalse;
9+
if (i -lastOneIndex <=k) {
10+
returnfalse;
11+
}else {
12+
lastOneIndex =i;
13+
}
1814
}
1915
}
2016
returntrue;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp