题目要求:
分析:
具体代码如下:
public class Solution {
public void flatten(TreeNode root) {
if(root == null)
return;
while(root != null) {
if(root.left == null) {
root = root.right;
} else {
TreeNode pre = root.left;
while(pre.right != null) {
pre = pre.right;
}
pre.right = root.right;
root.right = root.left;
root.left = null;
root = root.right;
}
}
}
}