Python | Leetcode Python题解之第284题窥视迭代器

题目:

题解:

python 复制代码
class PeekingIterator:
    def __init__(self, iterator):
        self.iterator = iterator
        self._next = iterator.next()
        self._hasNext = iterator.hasNext()

    def peek(self):
        return self._next

    def next(self):
        ret = self._next
        self._hasNext = self.iterator.hasNext()
        self._next = self.iterator.next() if self._hasNext else 0
        return ret

    def hasNext(self):
        return self._hasNext
相关推荐
飞翔的佩奇2 小时前
【完整源码+数据集+部署教程】【天线&水】舰船战舰检测与分类图像分割系统源码&数据集全套:改进yolo11-repvit
前端·python·yolo·计算机视觉·数据集·yolo11·舰船战舰检测与分类图像分割系统
木头左3 小时前
最大回撤约束下ETF多因子动态止盈参数校准方案
python
汤姆yu3 小时前
2026版基于python的协同过滤音乐推荐系统
开发语言·python
汤姆yu3 小时前
基于python的电子商务管理系统
开发语言·python
may_一一4 小时前
pycharm\python 安装下载
ide·python·pycharm
后台开发者Ethan4 小时前
FastAPI之 Python的类型提示
python·fastapi·ai编程
hello kitty w4 小时前
Python学习(11) ----- Python的泛型
windows·python·学习
没有梦想的咸鱼185-1037-16634 小时前
AI Agent结合机器学习与深度学习在全球气候变化驱动因素预测中的应用
人工智能·python·深度学习·机器学习·chatgpt·数据分析
im_AMBER5 小时前
Leetcode 33
算法·leetcode·职场和发展
测试19986 小时前
Selenium自动化测试+OCR-获取图片页面小说详解
自动化测试·软件测试·python·selenium·测试工具·ocr·测试用例