1 liner python each function


  • 0
    F
    class Vector2D(object):
    
    def __init__(self, vec2d):
        """
        Initialize your data structure here.
        :type vec2d: List[List[int]]
        """
        self.stack=reduce(lambda x, y:x+y, vec2d, [])
    
    def next(self):
        """
        :rtype: int
        """
        return self.stack.pop(0)
    
    def hasNext(self):
        """
        :rtype: bool
        """
        return self.stack != []
    

    Your Vector2D object will be instantiated and called as such:

    i, v = Vector2D(vec2d), []

    while i.hasNext(): v.append(i.next())


  • 0

    I don't think this is good, because list is copied at initialization which is O(n)


Log in to reply
 

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