g2601_2700.s2649_nested_array_generator.solution.ts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
The newest version!
// #Medium #2023_09_06_Time_138_ms_(86.92%)_Space_74.9_MB_(73.36%)
type MultidimensionalArray = (MultidimensionalArray | number)[]
function* inorderTraversal(arr: MultidimensionalArray): Generator {
for (const item of arr)
if (Array.isArray(item)) yield* inorderTraversal(item)
else yield item
}
/*
* const gen = inorderTraversal([1, [2, 3]]);
* gen.next().value; // 1
* gen.next().value; // 2
* gen.next().value; // 3
*/
export { inorderTraversal }
© 2015 - 2024 Weber Informatics LLC | Privacy Policy