071 Simplify Path

071 Simplify Path

有了split,天下我有

class Solution:
    # @param {string} path
    # @return {string}
    def simplifyPath(self, path):
        stack = []
        for s in path.split("/"):
            if s == "":
                continue
            elif s == "..":
                if stack != []:
                    stack.pop()
            elif s == ".":
                pass
            else:
                stack.append(s)
        return "/" + "/".join(stack)

 

posted @ 2015-07-20 14:19  dapanshe  阅读(99)  评论(0编辑  收藏  举报