参考代码:
class Solution: def flatten(self, nestedList): stack = [nestedList] flatten_list = [] while stack: top = stack.pop() if isinstance(top, list): for elem in reversed(top): stack.append(elem) else: flatten_list.append(top) return flatten_list