mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-22 05:26:46 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>请你在设计一个迭代器,在集成现有迭代器拥有的 <code>hasNext</code> 和 <code>next</code> 操作的基础上,还额外支持 <code>peek</code> 操作。</p>\n\n<p>实现 <code>PeekingIterator</code> 类:</p>\n\n<ul>\n\t<li><code>PeekingIterator(Iterator<int> nums)</code> 使用指定整数迭代器 <code>nums</code> 初始化迭代器。</li>\n\t<li><code>int next()</code> 返回数组中的下一个元素,并将指针移动到下个元素处。</li>\n\t<li><code>bool hasNext()</code> 如果数组中存在下一个元素,返回 <code>true</code> ;否则,返回 <code>false</code> 。</li>\n\t<li><code>int peek()</code> 返回数组中的下一个元素,但 <strong>不</strong> 移动指针。</li>\n</ul>\n\n<p><strong>注意:</strong>每种语言可能有不同的构造函数和迭代器 <code>Iterator</code>,但均支持 <code>int next()</code> 和 <code>boolean hasNext()</code> 函数。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\n[\"PeekingIterator\", \"next\", \"peek\", \"next\", \"next\", \"hasNext\"]\n[[[1, 2, 3]], [], [], [], [], []]\n<strong>输出:</strong>\n[null, 1, 2, 2, 3, false]\n\n<strong>解释:</strong>\nPeekingIterator peekingIterator = new PeekingIterator([1, 2, 3]); // [<u><strong>1</strong></u>,2,3]\npeekingIterator.next(); // 返回 1 ,指针移动到下一个元素 [1,<u><strong>2</strong></u>,3]\npeekingIterator.peek(); // 返回 2 ,指针未发生移动 [1,<u><strong>2</strong></u>,3]\npeekingIterator.next(); // 返回 2 ,指针移动到下一个元素 [1,2,<u><strong>3</strong></u>]\npeekingIterator.next(); // 返回 3 ,指针移动到下一个元素 [1,2,3]\npeekingIterator.hasNext(); // 返回 False\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 1000</code></li>\n\t<li><code>1 <= nums[i] <= 1000</code></li>\n\t<li>对 <code>next</code> 和 <code>peek</code> 的调用均有效</li>\n\t<li><code>next</code>、<code>hasNext</code> 和 <code>peek </code>最多调用 <code>1000</code> 次</li>\n</ul>\n\n<p> </p>\n\n<p><strong>进阶:</strong>你将如何拓展你的设计?使之变得通用化,从而适应所有的类型,而不只是整数型?</p>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 156,
|
||||
"likes": 157,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Binary Search Tree Iterator\", \"titleSlug\": \"binary-search-tree-iterator\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u4e8c\\u53c9\\u641c\\u7d22\\u6811\\u8fed\\u4ee3\\u5668\"}, {\"title\": \"Flatten 2D Vector\", \"titleSlug\": \"flatten-2d-vector\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u5c55\\u5f00\\u4e8c\\u7ef4\\u5411\\u91cf\"}, {\"title\": \"Zigzag Iterator\", \"titleSlug\": \"zigzag-iterator\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u952f\\u9f7f\\u8fed\\u4ee3\\u5668\"}]",
|
||||
@@ -125,7 +125,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"27.1K\", \"totalSubmission\": \"35.3K\", \"totalAcceptedRaw\": 27150, \"totalSubmissionRaw\": 35324, \"acRate\": \"76.9%\"}",
|
||||
"stats": "{\"totalAccepted\": \"27.6K\", \"totalSubmission\": \"35.9K\", \"totalAcceptedRaw\": 27570, \"totalSubmissionRaw\": 35907, \"acRate\": \"76.8%\"}",
|
||||
"hints": [
|
||||
"Think of \"looking ahead\". You want to cache the next element.",
|
||||
"Is one variable sufficient? Why or why not?",
|
||||
|
Reference in New Issue
Block a user