Why not using the split()?


  • 0
    W
    class Solution(object):
    	def simplifyPath(self, path):
    		l = path.split('/')
    		stack = []
    		for i in range(len(l)):
    			if l[i]!='' and l[i]!='.':
    				if l[i]=='..':
    					if len(stack)>0:
    						stack.pop()
    				else:
    					stack.append(l[i])
    		return '/'+'/'.join(stack)

Log in to reply
 

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