MCPcopy
hub / github.com/HuberTRoy/leetCode / simplifyPath

Method simplifyPath

String/SimplifyPath.py:37–64  ·  view source on GitHub ↗

:type path: str :rtype: str

(self, path)

Source from the content-addressed store, hash-verified

35
36class Solution(object):
37 def simplifyPath(self, path):
38 """
39 :type path: str
40 :rtype: str
41 """
42 path = re.sub(r'/+', '/', path)
43 if path[-1] == '/':
44 path = path[:-1]
45
46 path = path.split('/')
47
48 new_path = []
49 for i in path:
50 if i == '..':
51 try:
52 new_path.pop()
53 continue
54 except:
55 continue
56 if i =='.':
57 continue
58
59 new_path.append(i)
60
61 x = '/'.join(new_path)
62 if x and x[0] == '/':
63 return x
64 return '/' + x

Callers

nothing calls this directly

Calls 2

splitMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected