6 Line python Using Stack Beat %96.48


  • 0
    B
    class NestedIterator(object):
    
        def __init__(self, nestedList):
            self.st = nestedList[::-1]
    
        def next(self):
            return self.st.pop().getInteger()
    
        def hasNext(self):
            while self.st and  (not self.st[-1].isInteger()):
                node = self.st.pop()
                self.st += node.getList()[::-1]
            return True if self.st else False
    

Log in to reply
 

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