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