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

题目:

题解:

Go 复制代码
type PeekingIterator struct {
    iter     *Iterator
    _hasNext bool
    _next    int
}

func Constructor(iter *Iterator) *PeekingIterator {
    return &PeekingIterator{iter, iter.hasNext(), iter.next()}
}

func (it *PeekingIterator) hasNext() bool {
    return it._hasNext
}

func (it *PeekingIterator) next() int {
    ret := it._next
    it._hasNext = it.iter.hasNext()
    if it._hasNext {
        it._next = it.iter.next()
    }
    return ret
}

func (it *PeekingIterator) peek() int {
    return it._next
}
相关推荐
pixcarp1 小时前
知识库系统的内容资产闭环怎么设计
服务器·数据库·后端·golang
张忠琳4 小时前
【Go 1.26.4】Golang Select 深度解析
开发语言·后端·golang
提笔了无痕6 小时前
如何用Go实现整套RAG流程
开发语言·后端·golang
一只齐刘海的猫6 小时前
【Leetcode】找到字符串中所有字母异位词
算法·leetcode·职场和发展
wlsh156 小时前
Go 错误处理
golang
geovindu7 小时前
go: Generators Pattern
开发语言·后端·设计模式·golang·生成器模式
凌波粒8 小时前
LeetCode--108.将有序数组转换为二叉搜索树(二叉树)
算法·leetcode·职场和发展
兰令水8 小时前
leecodecode【面试150】【2026.6.13打卡-java版本】
java·算法·leetcode
临沂堇8 小时前
刷题日志 | Leetcode Hot 100 哈希
算法·leetcode·哈希算法
Navigator_Z11 小时前
LeetCode //C - 1096. Brace Expansion II
c语言·算法·leetcode