/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
TreeNode pre=null,head=null;
public TreeNode convertBiNode(TreeNode root) {
f(root);
if(pre!=null){
pre.right=null;
pre.left=null;
}
return head;
}
public void f(TreeNode root){
if(root==null) return;
f(root.left);
if(pre==null){
pre=root;
head=root;
}else{
pre.right=root;
pre.left=null;
pre=root;
}
f(root.right);
}
}