Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # @param A : string
- # @return a strings
- #path = "/home/", => "/home"
- #path = "/a/./b/../../c/", => "/c"
- import os
- class Solution:
- def abs_path(self, string):
- return os.path.abspath(string)
- def simplifyPath(self, A):
- stack = []
- result = ''
- path_list = A.split("/")
- for i in range(len(path_list)-1, 0, -1):
- if path_list[i] != '':
- stack.append(path_list[i])
- # stack :
- while len(stack) != 0:
- path = stack.pop()
- if path == "..":
- if len(stack) != 0:
- stack.pop()
- else:
- result += '/
- if path == ".":
- continue
- else:
- result += '/'+path
- return result
- s = Solution()
- print(s.simplifyPath("/../"))
- print(s.abs_path("/../"))
Advertisement
Add Comment
Please, Sign In to add comment