← 返回 roblox 的题目列表Flatten Nested Array
类型:qbank
Flatten a nested array structure into a single list while preserving left-to-right order.
Examples
Example 1:
Input: nested = [[1, 2, 3], [4, 5], [6]]
Output: [1, 2, 3, 4, 5, 6]
Explanation:
Each sub-array is concatenated in order.
Example 2:
Input: nested = [[1], [], [2, 3]]
Output: [1, 2, 3]
Explanation:
Empty sub-arrays contribute nothing.
Example 3:
Input: nested = []
Output: []
Constraints
0 <= nested.length <= 10^4
Leaves are 32-bit signed integers.
The grader uses depth-2 inputs (number[][]); your recursive solution should still generalize to arbitrary depth — that is what the interviewer evaluates.