@@ -35,40 +35,45 @@ int[] Retrieve(String start, String end, String granularity):
35
35
*/
36
36
public class _635 {
37
37
38
- /**credit: https://discuss.leetcode.com/topic/94449/concise-java-solution*/
39
- public static class LogSystem {
38
+ public static class Solution1 {
39
+ /**
40
+ * credit: https://discuss.leetcode.com/topic/94449/concise-java-solution
41
+ */
42
+ public static class LogSystem {
40
43
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
+ */
44
49
45
- List <String []>timestamps ;
46
- List <String >units ;
47
- int []indices ;
50
+ List <String []>timestamps ;
51
+ List <String >units ;
52
+ int []indices ;
48
53
49
- public LogSystem () {
50
- timestamps =new LinkedList <>();
51
- units =Arrays .asList ("Year" ,"Month" ,"Day" ,"Hour" ,"Minute" ,"Second" );
52
- indices =new int []{4 ,7 ,10 ,13 ,16 ,19 };
53
- }
54
+ public LogSystem () {
55
+ timestamps =new LinkedList <>();
56
+ units =Arrays .asList ("Year" ,"Month" ,"Day" ,"Hour" ,"Minute" ,"Second" );
57
+ indices =new int []{4 ,7 ,10 ,13 ,16 ,19 };
58
+ }
54
59
55
- public void put (int id ,String timestamp ) {
56
- timestamps .add (new String []{Integer .toString (id ),timestamp });
57
- }
60
+ public void put (int id ,String timestamp ) {
61
+ timestamps .add (new String []{Integer .toString (id ),timestamp });
62
+ }
58
63
59
- public List <Integer >retrieve (String s ,String e ,String gra ) {
60
- List <Integer >res =new LinkedList <>();
61
- int index =units .indexOf (gra );
62
- int stringEnd =indices [index ];
63
- for (String []timestamp :timestamps ) {
64
- if (timestamp [1 ].substring (0 ,stringEnd ).compareTo (s .substring (0 ,stringEnd )) >=0
65
- &×tamp [1 ].substring (0 ,stringEnd ).compareTo (e .substring (0 ,stringEnd )) <=0 ) {
66
- res .add (Integer .parseInt (timestamp [0 ]));
64
+ public List <Integer >retrieve (String s ,String e ,String gra ) {
65
+ List <Integer >res =new LinkedList <>();
66
+ int index =units .indexOf (gra );
67
+ int stringEnd =indices [index ];
68
+ for (String []timestamp :timestamps ) {
69
+ if (timestamp [1 ].substring (0 ,stringEnd ).compareTo (s .substring (0 ,stringEnd )) >=0
70
+ &×tamp [1 ].substring (0 ,stringEnd ).compareTo (e .substring (0 ,stringEnd )) <=0 ) {
71
+ res .add (Integer .parseInt (timestamp [0 ]));
72
+ }
67
73
}
74
+ return res ;
68
75
}
69
- return res ;
70
76
}
71
77
}
72
78
73
-
74
79
}