little naive solution


  • 0
    G
    public class logStorageSystem {
    	
    	Map<String[], Integer> mp = new HashMap<>();
    	
    	
    	public logStorageSystem() {
            
        }
        
        public void put(int id, String timestamp) {
            String[] arr = timestamp.split(":");
            mp.put(arr, id);
        }
        //2016:01:01:00:00:00  Year:Month:Day:Hour:Minute:Second
        public List<Integer> retrieve(String s, String e, String gra) {
            int toindex = 0;
            List<Integer> res = new ArrayList<>();
            
            
            if(gra.equals("Month")){
            	toindex = 1;
            }else if(gra.equals("Day")){
            	toindex = 2;
            }else if(gra.equals("Hour")){
            	toindex = 3;
            }else if(gra.equals("Minute")){
            	toindex = 4;
            }else if(gra.equals("Second")){
            	toindex = 5;
            }
            String[] startarr = s.split(":");
            String[] endarr = e.split(":");
            String starts = "";
            String ends = "";
            for(int i =0;i<=toindex;i++){
            	starts += startarr[i];
            	ends += endarr[i];
            }
            double start = Double.valueOf(starts);
            double end = Double.valueOf(ends);
            
            for(String[] timearr:mp.keySet()){
            	boolean isvalid = false;
            	String curtimes = "";
            	for(int i =0;i<=toindex;i++){
            		curtimes += timearr[i];
                }
            	double curtime = Double.valueOf(curtimes);
            	if(curtime>=start &&  curtime<=end){
            		res.add(mp.get(timearr));
            	}
            }
            return res;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.