My python solution, 56ms. Would interviewer be ok with using the split() function ?


  • 0
    I
    class Solution(object):
        def simplifyPath(self, path):
            """
            :type path: str
            :rtype: str
            """
            pathList = path.split("/")
            stack = []
            
            for elem in pathList:
                if elem == '..' and len(stack) != 0:
                    stack.pop()
                elif elem != '.' and elem != '' and elem != '..':
                    stack.append(elem)
                    
            return '/' + '/'.join(stack)

Log in to reply
 

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