My Python solution


  • 1
    C

    here is my python solution. The algorithm is simple using stack

    def simplifyPath(self, path):
            z = path.split("/")
            z = filter(lambda x: x != "" and x != ".",z)
            s = list();
            for x in z:
            	if(x != ".."):
            		s.append(x)
            	elif s:
            		s.pop()
            
            result = "/".join(s)
            return "/"+result

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.