Submission Detail

258 / 258 test cases passed.
Status:

Accepted

Runtime: 316 ms
Memory Usage: 13.6 MB
Submitted: 0 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0
5
10
15
20
25
30
35
40
45
2
4
6
8
python
Runtime (ms)
Distribution (%)

0
5
10
15
20
25
30
35
40
45
5
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

13450
13200
13250
13300
13350
13400
13500
13550
13600
13650
13700
5
10
15
20
25
30
python
You are here!
Your memory usage beats 53.49 % of python submissions.
Memory (KB)
Distribution (%)

13450
13200
13250
13300
13350
13400
13500
13550
13600
13650
13700
10
20
30
Zoom area by dragging across this chart

Invite friends to challenge Simplify Path


Submitted Code: 0 minutes ago

Language: python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class Solution(object):
def simplifyPath(self, path):
"""
:type path: str
:rtype: str
"""
if (path == "/" or path == "/." or path == "/.."):
return "/"
if (len(path) <= 1):
return "/"
i = 0
while (i < len(path)-1):
if (path == "/" or path == "/." or path == "/.."):
return "/"
if (path[i] == '/'):
if (path[i+1] == '.'):
# single '.'
if (i+1 == len(path)-1):
path = path[:i]
if (i+2 < len(path) and path[i+2] == '/'):
path = path[:i] + path[i+2:]
i = 0
continue
if (i+2 < len(path) and path[i+2] == '.'):
# double '.'
if (i+2 == 2 and path[3] == '/'):
path = path[3:]
i = 0
continue
if (i+3 < len(path) and path[i+3] == '/'):
k = i -1
while (path[k] != '/'):
k -= 1
path = path[:k] + path[i+3:]
i = 0
continue
elif (i+3 >= len(path)):
k = i -1
while (path[k] != '/'):
k -= 1
if (k == 0):
path = path[0]
else:
path = path[:k]
print(path)
i = 0
continue
# multiple '/'
if (i+1 < len(path) and path[i+1] == '/'):
k = i+1
while (k < len(path)-1 and path[k] == '/'):
k += 1
if (k == len(path)-1):
path = path[:i+1]
else:
path = path[:i+1] + path[k:]
print(path)
i = 0
continue
i += 1
if (len(path) > 1):
end = len(path)-1
while (end >= 0 and path[end] == '/'):
path = path[:end]
end -= 1
return path
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX