这道题目使用二叉树的中序遍历就可以了,保存上以节点和当前节点进行指向。
public class Solution {
TreeNode head, tep;
public TreeNode Convert(TreeNode pRootOfTree) {
if(pRootOfTree==null)
return null;
Convert1(pRootOfTree);
return head;
}
public void Convert1(TreeNode curr){
if(curr==null)
return;
Convert1(curr.left);
if(tep==null)
head = curr;
else
tep.right = curr;
curr.left = tep;
tep = curr;
Convert1(curr.right);
}
}