Skip to content

Commit c4c3443

Browse files
Create simplify_path.py
1 parent 2806c2f commit c4c3443

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

simplify_path.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from collections import deque
2+
class Solution:
3+
def simplifyPath(self, path: str) -> str:
4+
s = deque()
5+
for node in path.split('/'):
6+
if node == '..':
7+
if s:
8+
s.pop()
9+
elif node and node != '.':
10+
s.append(node)
11+
return "/" + "/".join(s)

0 commit comments

Comments
 (0)