题解 | #二叉搜索树与双向链表#
二叉搜索树与双向链表
http://www.nowcoder.com/practice/947f6eb80d944a84850b0538bf0ec3a5
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
*/
public class Solution {
TreeNode head = null;
TreeNode pre = null;
public TreeNode Convert(TreeNode pRootOfTree) {
dfs(pRootOfTree);
return head;
}
public void dfs(TreeNode cur){
if(cur == null){
return;
}
dfs(cur.left);
if(head != null){
pre.right = cur;
}else{
head = cur;
}
cur.left = pre;
pre = cur;
dfs(cur.right);
}
}
