# 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
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- TrieNode的建立尽量用haspmap来做,而不是array[256]。这样省空间,而且可以查找非字母(相比T...
- calculator会想到stack,不同题目的处理方式不一样227 Basic Calculator II Le...
- 先来看LRU Cache,LRU Cache的重点就是建立一个 map<key, list<>::iterator...
- 参考:http://www.cnblogs.com/grandyang/p/5999050.html 这两道题很像...
- LeetCode 26. Remove Duplicates from Sorted Array Given a ...