当前位置:网站首页>Journey of little black leetcode: 341. Flattening nested list iterator
Journey of little black leetcode: 341. Flattening nested list iterator
2022-07-24 04:31:00 【Xiaohei invincible】
Little black answer
# """
# 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 judges of C language classic exercises score the highest and lowest to get an average score
- 【2023芯动科技提前批笔试题】~ 题目及参考答案
- Engineer competency model and skill requirements
- C language: selective sorting method
- Basic syntax of MySQL DDL and DML and DQL
- Billiard simulator based on the integration of GL pipeline and ray tracing technology
- 一次线上事故,我顿悟了异步的精髓
- 数组力扣(持续更新)
- "Paper reproduction" bidaf code implementation process (3) model establishment
- An online accident, I suddenly realized the essence of asynchrony
猜你喜欢

"Paper reproduction" bidaf code implementation process (3) model establishment

C语言经典习题之猴子吃桃问题

postgresql源码学习(32)—— 检查点④-核心函数CreateCheckPoint

Where is the difficulty in attracting investment in the park? Inventory of difficulties and difficulties in attracting investment in industrial parks

The problem of monkeys eating peaches in classic exercises of C language

Write a search box with search tips

Shell语法(一)

Chery arizer 8 products are powerful, and "all excellent" is not for nothing

Logback log framework technology in project development

Design and implementation of data analysis platform for intelligent commerce
随机推荐
"Paper reproduction" bidaf code implementation process (3) model establishment
To -.---
【2023芯动科技提前批笔试题】~ 题目及参考答案
Introduction to the application fields and functions of bank virtual human technology
1.7.1 right and wrong problem (infix expression)
What is the general family of programmers working in first tier cities?
如何用STATA进行chowtest
postgresql源码学习(32)—— 检查点④-核心函数CreateCheckPoint
C语言:选择排序法
MOS cameraization and digitization "includes designation (contro. skilled
Codeforces Round #808 (Div. 2) A - D
Privacy protection federal learning framework supporting most irregular users
Application scenarios and schemes of common mechanical equipment safety virtual simulation system
Go language series - synergy GMP introduction - with ByteDance interpolation
Text attack methods open source code summary
C language: bubble sorting
C语言基础学习笔记
[untitled]
Determined by hardware (see official 2 and
Imitate today's headlines real-time news wechat applet project source code