@@ -35,40 +35,45 @@ int[] Retrieve(String start, String end, String granularity):
3535 */
3636public class _635 {
3737
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 {
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- 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+ }
5459
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+ }
5863
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- && timestamp [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+ && timestamp [1 ].substring (0 , stringEnd ).compareTo (e .substring (0 , stringEnd )) <= 0 ) {
71+ res .add (Integer .parseInt (timestamp [0 ]));
72+ }
6773 }
74+ return res ;
6875 }
69- return res ;
7076 }
7177 }
7278
73-
7479}
0 commit comments