python simple code

  • 0
    class Vector2D(object):
        def __init__(self, vec2d):
            Initialize your data structure here.
            :type vec2d: List[List[int]]
            self.vec = vec2d
            self.x = 0
            self.y = 0
        def next(self):
            :rtype: int
            if self.hasNext():
                res = self.vec[self.x][self.y]
                self.y += 1
                return res
        def hasNext(self):
            :rtype: bool
            if self.x == len(self.vec):
                return False
            if self.y == len(self.vec[self.x]):
                return self.hasNext()
            if self.vec[self.x][self.y]!=None:
                return True

Log in to reply

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