Skip to content

Commit 1deaf64

Browse files
authored
Create unix_path_resolution.py
1 parent 777f75a commit 1deaf64

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'''
2+
Given a Unix path, represented as a list of strings, return its resolved version.
3+
4+
In Unix, ".." means to go to the previous directory and "." means to stay
5+
on the current directory. By resolving, we mean to evaluate the two symbols so that we get the final directory we're currently in.
6+
'''
7+
8+
9+
class Solution:
10+
def solve(self, path):
11+
12+
stack = []
13+
14+
for s in path:
15+
if s == "..":
16+
if len(stack)> 0:
17+
stack.pop()
18+
elif s == ".":
19+
continue
20+
else:
21+
stack.append(s)
22+
print(stack)
23+
return stack
24+
25+
26+

0 commit comments

Comments
 (0)