Posted on 2023-04-12 22:53
Uriel 阅读(38)
评论(0) 编辑 收藏 引用 所属分类:
模拟 、
闲来无事重切Leet Code
将输入的文件地址改成标准形式,简单模拟
1 #71
2 #Runtime: 15 ms (Beats 93.49%)
3 #Memory: 13.7 MB (Beats 13.73%)
4
5 class Solution(object):
6 def simplifyPath(self, path):
7 """
8 :type path: str
9 :rtype: str
10 """
11 ans = []
12 sub_folders = path.split("/")
13 for sub_folder in sub_folders:
14 if sub_folder == "." or not sub_folder:
15 continue
16 elif sub_folder == "..":
17 if ans:
18 ans.pop()
19 else:
20 ans.append(sub_folder)
21 return "/" + "/".join(ans)