why my solution is not correct


  • 0
    J
    
    
    class LogSystem {
    public:
        LogSystem() {
            map["Year"]=4;map["Month"] = 7;map["Day"] = 10;
            map["Hour"]=13;map["Minutes"]=16;map["Second"]=19;
        }
        
        void put(int id, string timestamp) {
           res.push_back({id,timestamp});
        }
        
        vector<int> retrieve(string s, string e, string gra) {
            vector<int> out;
            s = s.substr(0,map[gra]);
            e = e.substr(0,map[gra]);
            for(int i = 0;i<res.size();i++)
            {
                if(insideRange(res[i].second,s,e, gra))
                    out.push_back(res[i].first);
            }
            return out;
        }
    private:
        unordered_map<string,int>map;
        vector<pair<int,string>> res;
        
        bool insideRange(string curr,string s,string e,string gra)
        {
            curr = curr.substr(0,map[gra]);
            return curr.compare(s)>=0&&curr.compare(e)<=0;
        } 
    };
    

Log in to reply
 

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