当前位置: 首页 > news >正文

力扣labuladong——一刷day40

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 一、力扣341. 扁平化嵌套列表迭代器


前言


N叉树的结构,构造迭代器

一、力扣341. 扁平化嵌套列表迭代器

/*** // This is the interface that allows for creating nested lists.* // You should not implement it, or speculate about its implementation* public interface NestedInteger {**     // @return true if this NestedInteger holds a single integer, rather than a nested list.*     public boolean isInteger();**     // @return the single integer that this NestedInteger holds, if it holds a single integer*     // Return null if this NestedInteger holds a nested list*     public Integer getInteger();**     // @return the nested list that this NestedInteger holds, if it holds a nested list*     // Return empty list if this NestedInteger holds a single integer*     public List<NestedInteger> getList();* }*/
public class NestedIterator implements Iterator<Integer> {LinkedList<NestedInteger> list;public NestedIterator(List<NestedInteger> nestedList) {list = new LinkedList<>(nestedList);}@Overridepublic Integer next() {return list.remove(0).getInteger();}@Overridepublic boolean hasNext() {while(!list.isEmpty() && !list.get(0).isInteger()){List<NestedInteger> first = list.remove(0).getList();for(int i = first.size()-1; i >= 0; i --){list.addFirst(first.get(i));}}return !list.isEmpty();}
}/*** Your NestedIterator object will be instantiated and called as such:* NestedIterator i = new NestedIterator(nestedList);* while (i.hasNext()) v[f()] = i.next();*/
http://www.lryc.cn/news/235155.html

相关文章:

  • 在VS Code中使用VIM
  • 注解【元数据,自定义注解等概念详解】(超简单的好吧)
  • vue-pdf在vue框架中的使用
  • Wordpress页面生成器:Elementor 插件制作网站页面教程(图文完整)
  • 完全随机设计的方差分析
  • 035、目标检测-物体和数据集
  • 【开源】基于Vue.js的社区买菜系统的设计和实现
  • 【双指针】复写0
  • 记录一些涉及到界的题
  • Linux秋招面试题
  • OPPO发布AndesGPT大模型;Emu Video和Emu Edit的新突破
  • 2311rust,到46版本更新
  • Rust根据条件删除相邻元素:dedup
  • 2023年(第六届)电力机器人应用与创新发展论坛-核心PPT资料下载
  • Android BitmapFactory.decodeResource读取原始图片装载成原始宽高Bitmap,Kotlin
  • 阿里云服务器 手动搭建WordPress(CentOS 8)
  • 竞赛 题目:基于深度学习的中文对话问答机器人
  • CCF ChinaSoft 2023 论坛巡礼|软件测试产教研融合论坛
  • 浅谈WPF之控件模板和数据模板
  • 微信小程序会议OA首页-开发说明创建项目关于flex布局关于尺寸单位(rpx)关于WXS轮播图会议信息
  • Linux上编译和安装SOFA23.06
  • 定时任务 Spring Task
  • golang 上传图片 --chatGPT
  • Android Studio 写一个Java调用c++ 的demo
  • Pandas数据操作_Python数据分析与可视化
  • 【Debug】查询的数据量比数据库中的数据量还要多
  • nodejs微信小程序-慢性胃炎健康管理系统的设计与实现-安卓-python-PHP-计算机毕业设计
  • 二十一、数组(1)
  • react hook 获取setState的新值
  • JVM判断对象是否存活之引用计数法、可达性分析