forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.py
34 lines (28 loc) · 800 Bytes
/
Solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Solution:
def lengthLongestPath(self, input: str) -> int:
i, n = 0, len(input)
ans = 0
stk = []
while i < n:
ident = 0
while input[i] == '\t':
ident += 1
i += 1
cur, isFile = 0, False
while i < n and input[i] != '\n':
cur += 1
if input[i] == '.':
isFile = True
i += 1
i += 1
# popd
while len(stk) > 0 and len(stk) > ident:
stk.pop()
if len(stk) > 0:
cur += stk[-1] + 1
# pushd
if not isFile:
stk.append(cur)
continue
ans = max(ans, cur)
return ans