concise solution c++


  • 0
    S
    class LogSystem {
    public:
        LogSystem() : _G({{"Year", 4}, {"Month", 7}, {"Day", 10},
                          {"Hour", 13}, {"Minute", 16}, {"Second", 19}}) {
            
        }
        
        void put(int id, string timestamp) {
            _M[timestamp] = id;
        }
        
        vector<int> retrieve(string s, string e, string gra) {
            vector<int> res;
            s = s.substr(0, _G[gra]);
            e = e.substr(0, _G[gra]);
            for(auto t : _M)
            {
                auto tt = t.first.substr(0, _G[gra]);            
                if(tt >= s && tt <= e)
                    res.push_back(t.second);
            }
            
            return res;
        }
    
    private:    
        unordered_map<string, int> _M;
        unordered_map<string, int> _G;
    };
    

Log in to reply
 

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