import java.util.*;
/**
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
*/
public class Solution {
ArrayList<TreeNode> res = new ArrayList<TreeNode>(); //作为存储数据(因为不让开新的节点)
public TreeNode Convert(TreeNode pRootOfTree) {
if(pRootOfTree == null) return null; //临界值非空判断
sol(pRootOfTree);
for(int i =0 ; i<res.size()-1;i++){ //对集合里的节点进行连接
res.get(i).right = res.get(i+1);
res.get(i+1).left = res.get(i);
}
return res.get(0);
}
public TreeNode sol(TreeNode root){
if(root == null) return null;
TreeNode left = sol(root.left); //因为是中序遍历,所以在left和right之间进行节点的存储
res.add(root);
TreeNode right = sol(root.right);
return root;
}
}
