my python AC solution


  • 0
    1
    import collections,re
    
    class Solution(object):
        def lengthLongestPath(self, input):
            dic=collections.defaultdict(lambda:"")
            arr=input.split("\n")
            res=0
            for i in xrange(len(arr)):
                count=arr[i].count("\t")
                arr[i]=dic[count-1]+re.sub("\\t+","/",arr[i])
                if "." in arr[i]:
                    res=max(res,len(arr[i]))
                dic[count]=arr[i]
            return res
    

Log in to reply
 

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