[LeetCode][Python] 341. Flatten Nested List Iterator

티스토리 메뉴 펼치기 댓글수0

프로그래밍/LeetCode

[LeetCode][Python] 341. Flatten Nested List Iterator

snoopybox
댓글수0

Problem :

https://leetcode.com/problems/flatten-nested-list-iterator/


My Solution :

class NestedIterator(object):

def __init__(self, nestedList):
def generator(nestedList):
for item in nestedList:
if item.isInteger():
yield item.getInteger()
else:
for yielded in generator(item.getList()):
yield yielded

self.generator = generator(nestedList)

def next(self):
return self.value

def hasNext(self):
self.value = next(self.generator, None)
return self.value is not None
맨위로

https://www.snoopybox.co.kr/1965

신고하기