题目:
题解:
class Solution:def lengthLongestPath(self, input: str) -> int:ans, i, n = 0, 0, len(input)level = [0] * (n + 1)while i < n:# 检测当前文件的深度depth = 1while i < n and input[i] == '\t':depth += 1i += 1# 统计当前文件名的长度length, isFile = 0, Falsewhile i < n and input[i] != '\n':if input[i] == '.':isFile = Truelength += 1i += 1i += 1 # 跳过换行符if depth > 1:length += level[depth - 1] + 1if isFile:ans = max(ans, length)else:level[depth] = lengthreturn ans