標籤:XA 問題 elements calling 取出 false 模板 lin 思想
[抄題]:
Given a nested list of integers, implement an iterator to flatten it.
Each element is either an integer, or a list -- whose elements may also be integers or other lists.
Example 1:
Given the list [[1,1],2,[1,1]],
By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,1,2,1,1].
Example 2:
Given the list [1,[4,[6]]],
By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,4,6].
[暴力解法]:
時間分析:
空間分析:
[最佳化後]:
時間分析:
空間分析:
[奇葩輸出條件]:
[奇葩corner case]:
[思維問題]:
不知道.next 和 .hasnext有啥區別:取出來、只是看看有沒有
[一句話思路]:
[輸入量]:空: 正常情況:特大:特小:程式裡處理到的特殊情況:異常情況(不合法不合理的輸入):
[畫圖]:
[一刷]:
[二刷]:
[三刷]:
[四刷]:
[五刷]:
[五分鐘肉眼debug的結果]:
[總結]:
[複雜度]:Time complexity: O() Space complexity: O()
[英文資料結構或演算法,為什麼不用別的資料結構或演算法]:
只有stack才能一次取出來一層,數組不能直接取出來一層。所以用stack。
stack有
.getInteger()
.getList()
方法
[演算法思想:遞迴/分治/貪心]:
[關鍵模板化代碼]:
[其他解法]:
[Follow Up]:
[LC給出的題目變變變]:
[代碼風格] :
341. Flatten Nested List Iterator展開多層數組