Coincise python solution

  • 0

    class NestedIterator(object):

    def __init__(self, nestedList):
        Initialize your data structure here.
        :type nestedList: List[NestedInteger]
        self.mylist = nestedList
    def next(self):
        :rtype: int
        return self.mylist.pop(0).getInteger()
    def hasNext(self):
        :rtype: bool
        while self.mylist:
            if self.mylist[0].isInteger():
                return True;
            else :
                lst = self.mylist[0].getList()
                if not lst:
                else :
                    self.mylist = lst+self.mylist[1:]
        return False

Log in to reply

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