解题思路:
class Solution {List<TreeNode> list = new ArrayList<>();public void flatten(TreeNode root) {recur(root);for (int i = 1; i < list.size(); i++) {TreeNode pre = list.get(i - 1);TreeNode cur = list.get(i);pre.left = null;pre.right = cur;}}public void recur(TreeNode root) {if (root == null) return;list.add(root);recur(root.left);recur(root.right);}
}