当前位置:网站首页>小黑leetcode之旅:341. 扁平化嵌套列表迭代器
小黑leetcode之旅:341. 扁平化嵌套列表迭代器
2022-07-22 19:35:00 【小黑无敌】
小黑答案
# """
# This is the interface that allows for creating nested lists.
# You should not implement it, or speculate about its implementation
# """
#class NestedInteger:
# def isInteger(self) -> bool:
# """
# @return True if this NestedInteger holds a single integer, rather than a nested list.
# """
#
# def getInteger(self) -> int:
# """
# @return the single integer that this NestedInteger holds, if it holds a single integer
# Return None if this NestedInteger holds a nested list
# """
#
# def getList(self) -> [NestedInteger]:
# """
# @return the nested list that this NestedInteger holds, if it holds a nested list
# Return None if this NestedInteger holds a single integer
# """
class NestedIterator:
def __init__(self, nestedList: [NestedInteger]):
self.arr = []
print(nestedList)
self.get_list(nestedList)
self.i = 0
self.len = len(self.arr)
def get_list(self,nestedList):
for item in nestedList:
if item.getList():
self.get_list(item.getList())
elif item.isInteger():
self.arr.append(item.getInteger())
def next(self) -> int:
item = self.arr[self.i]
self.i += 1
return item
def hasNext(self) -> bool:
if self.i < self.len:
return True
else:
return False
# Your NestedIterator object will be instantiated and called as such:
# i, v = NestedIterator(nestedList), []
# while i.hasNext(): v.append(i.next())

边栏推荐
- The synchronized lock that I have been wondering about is so simple!
- CV语义分割模型小抄(1)
- gpu和cpu有什么区别不同 电脑gpu含义介绍
- 电脑屏幕发黄怎么回事 显示器屏幕发黄是什么原因及排查方法
- Stability control and Simulation of double inverted pendulum system (matlab/simulink)
- js中的迭代器与生成器(详解)
- How to embed the monitoring image into wechat official account for live broadcast
- 2021-03-01
- 无法删除文件提示找不到指定文件导致文件无法删除的解决方法
- (ros_melody) using rviz for boundingbox visualization
猜你喜欢

Stability control and Simulation of double inverted pendulum system (matlab/simulink)

Electromagnetic field and electromagnetic wave experiment 4. Be familiar with the application of CST Studio Software in the electromagnetic field

LiveGBS-摄像机网页低延时无插件直播实现

Flink数据源拆解分析(WikipediaEditsSource)

弱网优化(SharePreference)原理+实战剖析

Opencv one dimensional frequency domain filter

引擎提示Alias HeroDB跟游戏引擎启动异常怎么解决?

Priority of STL functor_ Queue simulation implementation

Realize the national standard gb28181 streaming media service solution

The synchronized lock that I have been wondering about is so simple!
随机推荐
MySQL --- 子查询 - 子查询概念、规范、分类
Demo19- (to be updated)
TCP waves four times
删除文件时需要system权限怎么办 你需要来自system的权限才能删除的解决办法
HCDE城市闭门会南京站成功举办
百度钱包帮你还信用卡 跨行还款0手续费 实时到帐 新人奖励5元
AWS使用EC2降低DeepRacer的训练成本DeepRacer-for-cloud的实践操作
记事本文件太大打不开怎么办?TXT文件太大无法打开现象的解决办法介绍
MySQL - sub query - sub query concept, specification, classification
bin文件怎么打开查看?路由器备份出来的bin文件读取方法图解
Kali tools sqlmap common usage
电磁场与电磁波实验四 熟悉CST Studio软件在电磁领域的应用
ABAP ALV步骤
abap ALV总结整理
IO流原理及流的分类
电脑下载的软件不在桌面显示怎么办 解决安装后的软件不在桌面问题
Sharepreference principle + practical analysis
Redis增强
华泰证券股票开户怎么样安全吗
Flink数据源拆解分析(WikipediaEditsSource)