Python with generator


  • 0
    J
    class Vector2D(object):
        def __init__(self, vec2d):
            self.gen = (x for row in vec2d for x in row)
    
        def next(self):
            return self._next
            
        def hasNext(self):
            self._next = next(self.gen, None)
            return self._next is not None
    

Log in to reply
 

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