C++ 9 lines unordered_map


  • 0
        int lengthLongestPath(string input) {
            int maxlen=0;
            stringstream ss(input);
            unordered_map<int,int>m;
            for(string s;getline(ss,s,'\n');){
                int lev=s.rfind('\t')+1;
                m[lev]=m[lev-1]+s.size()-lev;
                if(s.find('.')!=string::npos) maxlen=max(maxlen,m[lev]+lev);
            }
            return maxlen;
        }
    

Log in to reply
 

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