Skip to content

Commit 19d486c

Browse files
Question 71
1 parent e0a02ee commit 19d486c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

71. Simplify Path.py

+15
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,18 @@
3636
Output: "/a/b/c"
3737
'''
3838

39+
class Solution:
40+
def simplifyPath(self, path: str) -> str:
41+
stack = []
42+
string = path.split('/')
43+
for i in range(len(string)):
44+
if string[i]!='':
45+
if string[i]=='..':
46+
if len(stack)>0:
47+
stack.pop()
48+
elif string[i]=='.':
49+
pass
50+
else:
51+
stack.append(string[i])
52+
53+
return '/'+'/'.join(stack)

0 commit comments

Comments
 (0)