Skip to content

Commit 46afdba

Browse files
author
yangdi.yd
committed
add file flatten_nested_list_iterator.py
1 parent 46424e2 commit 46afdba

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# """
2+
# This is the interface that allows for creating nested lists.
3+
# You should not implement it, or speculate about its implementation
4+
# """
5+
#class NestedInteger(object):
6+
# def isInteger(self):
7+
# """
8+
# @return True if this NestedInteger holds a single integer, rather than a nested list.
9+
# :rtype bool
10+
# """
11+
#
12+
# def getInteger(self):
13+
# """
14+
# @return the single integer that this NestedInteger holds, if it holds a single integer
15+
# Return None if this NestedInteger holds a nested list
16+
# :rtype int
17+
# """
18+
#
19+
# def getList(self):
20+
# """
21+
# @return the nested list that this NestedInteger holds, if it holds a nested list
22+
# Return None if this NestedInteger holds a single integer
23+
# :rtype List[NestedInteger]
24+
# """
25+
26+
class NestedIterator(object):
27+
28+
def __init__(self, nestedList):
29+
"""
30+
Initialize your data structure here.
31+
:type nestedList: List[NestedInteger]
32+
"""
33+
34+
35+
def next(self):
36+
"""
37+
:rtype: int
38+
"""
39+
40+
41+
def hasNext(self):
42+
"""
43+
:rtype: bool
44+
"""
45+
46+
47+
# Your NestedIterator object will be instantiated and called as such:
48+
# i, v = NestedIterator(nestedList), []
49+
# while i.hasNext(): v.append(i.next())

0 commit comments

Comments
 (0)