Uriel's Corner

Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
posts - 0, comments - 50, trackbacks - 0, articles - 594
将输入的文件地址改成标准形式,简单模拟


 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)

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理