Concise loopless C++ solution

  • 0

    I like loopless solution because it is cleaner :D

    multimap<string, int> m;
    void put(int id, string timestamp) { m.emplace(timestamp, id); }
    static int graToOffset(string& gra){
            case 'Y': return 5;
            case 'M': return gra[1] == 'o' ? 8 : 17;
            case 'D': return 11;
            case 'H': return 14;
            default: return 19;
    vector<int> retrieve(string s, string e, string gra) {
        auto offset = graToOffset(gra);
        s.resize(offset), e.resize(offset), e += '9';
        vector<int> result;
        transform(m.lower_bound(s), m.lower_bound(e), back_inserter(result), [](const pair<string,int>& p){
            return p.second;
        return result;

Log in to reply

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