[bug]
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public TreeNode convertBiNode(TreeNode root) {
if(root==null){
return null;
}
List<TreeNode> list = new ArrayList<>();
dfs(root, list);
TreeNode ret = list.get(0);
while(!list.isEmpty()){
TreeNode cur = list.remove(0);
if(list.isEmpty()){
break;
}
cur.right = list.get(0);
cur.left = null;
}
return ret;
}
void dfs(TreeNode root, List list){
if(root==null){
return;
}
dfs(root.left, list);
list.add(root);
dfs(root.right, list);
}
}```