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

Commit65a8987

Browse files
refactor 635
1 parent55e7fe3 commit65a8987

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

‎src/main/java/com/fishercoder/solutions/_635.java

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,45 @@ int[] Retrieve(String start, String end, String granularity):
3535
*/
3636
publicclass_635 {
3737

38-
/**credit: https://discuss.leetcode.com/topic/94449/concise-java-solution*/
39-
publicstaticclassLogSystem {
38+
publicstaticclassSolution1 {
39+
/**
40+
* credit: https://discuss.leetcode.com/topic/94449/concise-java-solution
41+
*/
42+
publicstaticclassLogSystem {
4043

41-
/**These indices denote and string endings of timestamps of different granularity, i.e.
42-
* timestamp[1] in timestamps: "2017:01:01:22:59:59"
43-
* -> 2017: 4, 01: 7, 01: 10, 22: 13, 59: 16, 59: 19*/
44+
/**
45+
* These indices denote and string endings of timestamps of different granularity, i.e.
46+
* timestamp[1] in timestamps: "2017:01:01:22:59:59"
47+
* -> 2017: 4, 01: 7, 01: 10, 22: 13, 59: 16, 59: 19
48+
*/
4449

45-
List<String[]>timestamps;
46-
List<String>units;
47-
int[]indices;
50+
List<String[]>timestamps;
51+
List<String>units;
52+
int[]indices;
4853

49-
publicLogSystem() {
50-
timestamps =newLinkedList<>();
51-
units =Arrays.asList("Year","Month","Day","Hour","Minute","Second");
52-
indices =newint[]{4,7,10,13,16,19};
53-
}
54+
publicLogSystem() {
55+
timestamps =newLinkedList<>();
56+
units =Arrays.asList("Year","Month","Day","Hour","Minute","Second");
57+
indices =newint[]{4,7,10,13,16,19};
58+
}
5459

55-
publicvoidput(intid,Stringtimestamp) {
56-
timestamps.add(newString[]{Integer.toString(id),timestamp});
57-
}
60+
publicvoidput(intid,Stringtimestamp) {
61+
timestamps.add(newString[]{Integer.toString(id),timestamp});
62+
}
5863

59-
publicList<Integer>retrieve(Strings,Stringe,Stringgra) {
60-
List<Integer>res =newLinkedList<>();
61-
intindex =units.indexOf(gra);
62-
intstringEnd =indices[index];
63-
for (String[]timestamp :timestamps) {
64-
if (timestamp[1].substring(0,stringEnd).compareTo(s.substring(0,stringEnd)) >=0
65-
&&timestamp[1].substring(0,stringEnd).compareTo(e.substring(0,stringEnd)) <=0) {
66-
res.add(Integer.parseInt(timestamp[0]));
64+
publicList<Integer>retrieve(Strings,Stringe,Stringgra) {
65+
List<Integer>res =newLinkedList<>();
66+
intindex =units.indexOf(gra);
67+
intstringEnd =indices[index];
68+
for (String[]timestamp :timestamps) {
69+
if (timestamp[1].substring(0,stringEnd).compareTo(s.substring(0,stringEnd)) >=0
70+
&&timestamp[1].substring(0,stringEnd).compareTo(e.substring(0,stringEnd)) <=0) {
71+
res.add(Integer.parseInt(timestamp[0]));
72+
}
6773
}
74+
returnres;
6875
}
69-
returnres;
7076
}
7177
}
7278

73-
7479
}

‎src/test/java/com/fishercoder/_635Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
* Created by fishercoder on 9/9/17.
1616
*/
1717
publicclass_635Test {
18-
privatestatic_635.LogSystemlogSystem;
18+
privatestatic_635.Solution1.LogSystemlogSystem;
1919
privatestaticList<Integer>expected;
2020

2121
@BeforeClass
2222
publicstaticvoidsetup() {
23-
logSystem =new_635.LogSystem();
23+
logSystem =new_635.Solution1.LogSystem();
2424
}
2525

2626
@Before
2727
publicvoidclear() {
28-
logSystem =new_635.LogSystem();
28+
logSystem =new_635.Solution1.LogSystem();
2929
expected =newArrayList<>();
3030
}
3131

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp