标签:eve for while str pat ret ack turn add
使用栈
class Solution:
def lengthLongestPath(self, input: str) -> int:
input = input + ‘\n‘ # add trailing dummy \n
stack = []
level = 1
current = ‘‘
result = 0
for i in range(len(input)):
if input[i] == ‘\n‘:
while level <= len(stack):
stack.pop()
stack.append(current)
if ‘.‘ in current: # file
length = len(‘\\‘.join(stack))
result = max(length, result)
current = ‘‘
level = 1
elif input[i] == ‘\t‘:
level += 1
else:
current += input[i]
return result
[leetcode]Longest Absolute File Path
标签:eve for while str pat ret ack turn add
原文地址:https://www.cnblogs.com/lautsie/p/12271474.html