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

参考:https://leetcode-cn.com/problems/longest-absolute-file-path/solution/pythonjian-dan-shi-xian-by-tian-jing-cheng-2/

算法思路:栈。

posted on 2020-04-09 10:34  Sempron2800+  阅读(155)  评论(0编辑  收藏  举报