1 class Solution(object): 2 def lengthLongestPath(self, input): 3 """ 4 :type input: str 5 :rtype: int 6 """ 7 input = input.split('\n') 8 res = 0 9 stack = list() 10 for i in input: 11 d = i.count('\t') 12 i = i[d:] 13 while len(stack) > d: 14 stack.pop() 15 if '.' in i: 16 cur = len(i) + len(stack) 17 for s in stack: 18 cur += len(s) 19 res = max(res, cur) 20 else: 21 stack.append(i) 22 return res
算法思路:栈。