今天刷了一道题,对一个二叉树进行前序遍历:根节点--》左子树节点--》右子树节点。

题目要求将一棵树的每个非Null节点的值用一个List列表返回;
我的思路:执行函数创建List并加入当前值,因为函数是递归调用的,会生成N多个List,只需要将这N个List合并为一个List,一层一层的返回就可以了。


今天刷了一道题,对一个二叉树进行前序遍历:根节点--》左子树节点--》右子树节点。
题目要求将一棵树的每个非Null节点的值用一个List列表返回;
我的思路:执行函数创建List并加入当前值,因为函数是递归调用的,会生成N多个List,只需要将这N个List合并为一个List,一层一层的返回就可以了。