Who can tell me whether this piece of code make sense during a real interview?


  • 0
    class NestedIterator(object):
        def __init__(self, nestedList):
            self.list, self.idx = [], 0
            def iteration(list):
                if list.isInteger():
                    self.list.append(list.getInteger())
                    return
                lst = list.getList()
                for l in lst:
                    iteration(l)
            for l in nestedList:
                iteration(l)
            
        
        def next(self):
            ans = self.list[self.idx]
            self.idx += 1
            return ans
    
        def hasNext(self):
            return self.idx < len(self.list)
    

Log in to reply
 

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