Easy O(n) in Python


#1

class Solution:
# @param A : string
# @return a strings
def simplifyPath(self, A):
x=A.split("/")
res=[]
ch=[’.’, “…”, “”]
for i in range(len(x)):
if x[i] not in ch:
res.append(x[i])

        else:
            if x[i]=="..":
                if res:
                    res.pop()
        
    return "/"+"/".join(res)