Python simulation


  • 0
    class Solution(object):
        def lengthLongestPath(self, input):
            lines, stack, ans = input.split('\n'), [], 0
            for i in xrange(len(lines)):
                cnt = lines[i].count('\t')
                while len(stack) > cnt:
                    stack.pop()
                stack.append(''.join(lines[i].split('\t')))
                if '.' in lines[i]:
                    tmp = 0
                    for i in xrange(len(stack)):
                        tmp += len(stack[i])
                    tmp += len(stack) - 1
                    ans = max(ans, tmp)
            return ans
    

Log in to reply
 

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