C++ clean code, 0ms


  • 0
    C
        int lengthLongestPath(string input) {
            int level[200] = {0};
            stringstream ss(input);
            string token = "";
            int ans = 0;
            while(getline(ss, token, '\n')) {
                int lev = 1;
                bool isFile = false;
                for(char c : token) {
                    if(c == '\t') lev++;
                    else if(c == '.') isFile = true;
                }
                level[lev] = token.length() - (lev-1) + level[lev-1];
                
                if(isFile) {
                    ans = max(ans, level[lev] + lev - 1);
                }
                token = "";
            }
            return ans;
        }
    

Log in to reply
 

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