美文网首页
LeetCode:284

LeetCode:284

作者: hxc92 | 来源:发表于2017-11-14 15:09 被阅读0次
    # Below is the interface for Iterator, which is already defined for you.
    #
    # class Iterator(object):
    #     def __init__(self, nums):
    #         """
    #         Initializes an iterator object to the beginning of a list.
    #         :type nums: List[int]
    #         """
    #
    #     def hasNext(self):
    #         """
    #         Returns true if the iteration has more elements.
    #         :rtype: bool
    #         """
    #
    #     def next(self):
    #         """
    #         Returns the next element in the iteration.
    #         :rtype: int
    #         """
    
    class PeekingIterator(object):
        def __init__(self, iterator):
            """
            Initialize your data structure here.
            :type iterator: Iterator
            """
            
    
        def peek(self):
            """
            Returns the next element in the iteration without advancing the iterator.
            :rtype: int
            """
            
    
        def next(self):
            """
            :rtype: int
            """
            
    
        def hasNext(self):
            """
            :rtype: bool
            """
            
    
    # Your PeekingIterator object will be instantiated and called as such:
    # iter = PeekingIterator(Iterator(nums))
    # while iter.hasNext():
    #     val = iter.peek()   # Get the next element but not advance the iterator.
    #     iter.next()         # Should return the same value as [val].
    

    相关文章

      网友评论

          本文标题:LeetCode:284

          本文链接:https://www.haomeiwen.com/subject/yxhfvxtx.html