Simply Python solution using zip function

  • 0
    class ZigzagIterator(object):
        def __init__(self, v1, v2):
            Initialize your data structure here.
            :type v1: List[int]
            :type v2: List[int]
            self.idx = 0
   = [x for pair in zip(v1, v2) for x in pair]
            if len(v1) > len(v2):
        def next(self):
            :rtype: int
            if self.hasNext():
                res =[self.idx]
                self.idx += 1
                return res
                return None
        def hasNext(self):
            :rtype: bool
            return self.idx < len(

Log in to reply

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