classLogSystem:def__init__(self):self.logs=[]self.d={"Year":4,"Month":7,"Day":10,"Hour":13,"Minute":16,"Second":19,}defput(self,id:int,timestamp:str)->None:self.logs.append((id,timestamp))defretrieve(self,start:str,end:str,granularity:str)->List[int]:i=self.d[granularity]return[idforid,tsinself.logsifstart[:i]<=ts[:i]<=end[:i]]# Your LogSystem object will be instantiated and called as such:# obj = LogSystem()# obj.put(id,timestamp)# param_2 = obj.retrieve(start,end,granularity)
classLogSystem{privateList<Log>logs=newArrayList<>();privateMap<String,Integer>d=newHashMap<>();publicLogSystem(){d.put("Year",4);d.put("Month",7);d.put("Day",10);d.put("Hour",13);d.put("Minute",16);d.put("Second",19);}publicvoidput(intid,Stringtimestamp){logs.add(newLog(id,timestamp));}publicList<Integer>retrieve(Stringstart,Stringend,Stringgranularity){List<Integer>ans=newArrayList<>();inti=d.get(granularity);Strings=start.substring(0,i);Stringe=end.substring(0,i);for(varlog:logs){Stringt=log.ts.substring(0,i);if(s.compareTo(t)<=0&&t.compareTo(e)<=0){ans.add(log.id);}}returnans;}}classLog{intid;Stringts;Log(intid,Stringts){this.id=id;this.ts=ts;}}/** * Your LogSystem object will be instantiated and called as such: * LogSystem obj = new LogSystem(); * obj.put(id,timestamp); * List<Integer> param_2 = obj.retrieve(start,end,granularity); */
classLogSystem{public:LogSystem(){d["Year"]=4;d["Month"]=7;d["Day"]=10;d["Hour"]=13;d["Minute"]=16;d["Second"]=19;}voidput(intid,stringtimestamp){logs.push_back({id,timestamp});}vector<int>retrieve(stringstart,stringend,stringgranularity){vector<int>ans;inti=d[granularity];autos=start.substr(0,i);autoe=end.substr(0,i);for(auto&[id,ts]:logs){autot=ts.substr(0,i);if(s<=t&&t<=e){ans.emplace_back(id);}}returnans;}private:vector<pair<int,string>>logs;unordered_map<string,int>d;};/** * Your LogSystem object will be instantiated and called as such: * LogSystem* obj = new LogSystem(); * obj->put(id,timestamp); * vector<int> param_2 = obj->retrieve(start,end,granularity); */
typeLogSystemstruct{logs[]pairdmap[string]int}funcConstructor()LogSystem{d:=map[string]int{"Year":4,"Month":7,"Day":10,"Hour":13,"Minute":16,"Second":19,}returnLogSystem{[]pair{},d}}func(this*LogSystem)Put(idint,timestampstring){this.logs=append(this.logs,pair{id,timestamp})}func(this*LogSystem)Retrieve(startstring,endstring,granularitystring)(ans[]int){i:=this.d[granularity]s,e:=start[:i],end[:i]for_,log:=rangethis.logs{t:=log.ts[:i]ifs<=t&&t<=e{ans=append(ans,log.id)}}return}typepairstruct{idinttsstring}/** * Your LogSystem object will be instantiated and called as such: * obj := Constructor(); * obj.Put(id,timestamp); * param_2 := obj.Retrieve(start,end,granularity); */