pre记录上次的节点,head记录头节点
public class Solution {
TreeNode head = null,pre =null;
public void dfs(TreeNode root){
if(root == null)return;
dfs(root.left);
if(head == null)head = root;
else pre.right = root;
root.left = pre;
pre = root;
dfs(root.right);
}
public TreeNode Convert(TreeNode pRootOfTree) {
if(pRootOfTree == null)return null;
dfs(pRootOfTree);
return head;
}
}