Java 161ms beats all Java submissions so far


  • 0
    Z
    public class LogSystem {
        HashMap<String,Integer> size = new HashMap<String,Integer>();
        HashMap<Integer, String> log = new HashMap<Integer, String>();
        public LogSystem() {
            size.put("Year",4);
            size.put("Month",7);
            size.put("Day",10);
            size.put("Hour",13);
            size.put("Minute",16);
            size.put("Second",19);
            
        }
        
        public void put(int id, String timestamp) {
            log.put(id,timestamp);
        }
        List<Integer> result = new ArrayList<Integer>();
        public List<Integer> retrieve(String s, String e, String gra) {
            result.clear();
            int sz = size.get(gra);
            String start = s.substring(0,sz);
            String end = e.substring(0,sz);
            for(Integer i : log.keySet()){
                String str = (String) log.get(i);
                String cur = str.substring(0,sz);
                if(cur.compareTo(start)>=0 && cur.compareTo(end)<=0){
                    result.add(i);
                }
            }
            return result;
        }
    }
    

Log in to reply
 

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