classNestedInteger:defisInteger(self)->bool:""" @return True if this NestedInteger holds a single integer, rather than a nested list."""defgetInteger(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"""defgetList(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"""
所以用的时候,只能用这三个api来获取数据。。
做的方法,是一进来先递归展开数据,然后next的时候一个个pop出去
Runtime: 72 ms, faster than 43.64% of Python3 online submissions for Flatten Nested List Iterator. Memory Usage: 16.4 MB, less than 100.00% of Python3 online submissions for Flatten Nested List Iterator.
迭代器版本
Runtime: 64 ms, faster than 84.98% of Python3 online submissions for Flatten Nested List Iterator.
Memory Usage: 16.5 MB, less than 100.00% of Python3 online submissions for Flatten Nested List Iterator.