其他分享
首页 > 其他分享> > 388. Longest Absolute File Path

388. Longest Absolute File Path

作者:互联网

class Solution {
    public int lengthLongestPath(String input) {
        String [] arr=input.split("\n");
        int [] lens= new int[arr.length];
       
        int max=0;
        for(String s:arr){
            int lastBackT= s.lastIndexOf("\t");
            int level = lastBackT+1; 
            int parentLen = level==0? 0: lens[level-1]+1;
            int nameLen = s.length()-lastBackT-1;
            lens[level] = parentLen+nameLen;
            if(s.contains("."))
            {
                max = Math.max(max,lens[level]);
            }
        }
        
        return max;
    }
}

The first thought is DFS, however, we're able to deal it with array

标签:arr,lastBackT,level,int,max,lens,Longest,388,Path
来源: https://www.cnblogs.com/zg1005/p/11987302.html