Java simple solution


  • 2
    L
    public int lengthLongestPath(String input) {
        int longest = 0;
        String[] lines = input.split("\n");
        int[] lens = new int[lines.length+1];
        for(String line: lines) {
            String[] subs = line.split("\t");
            String cur = subs[subs.length-1];
            int len = lens[subs.length-1] + cur.length() + 1;
            if(cur.contains(".")) longest = Math.max(longest, len-1);
            else lens[subs.length] = len;
        }
        return longest;
    }
    
    

Log in to reply
 

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