simple python solution that beats 92%


  • 0
    L
    class Vector2D(object):
    
        def __init__(self, vec2d):
            """
            Initialize your data structure here.
            :type vec2d: List[List[int]]
            """
            self.idx = 0
            if len(vec2d) == 0:
                self.arr = []
            else:
                self.arr = reduce(lambda x, y: x + y, vec2d)
    
        def next(self):
            """
            :rtype: int
            """
            ret = self.arr[self.idx]
            self.idx += 1
            return ret
    
        def hasNext(self):
            """
            :rtype: bool
            """
            return self.idx < len(self.arr)
    

Log in to reply
 

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