public TreeNode addOneRow(TreeNode root, int v, int d) { if (d==1) { TreeNode res = new TreeNode(v); res.left = root; return res; } helper(root,v,d-1,1); return root; } public void helper(TreeNode root, int v, int d,int cur) { if (root==null) return; if (cur==d) { TreeNode l = root.left; TreeNode r = root.right; root.left = new TreeNode(v); root.right = new TreeNode(v); root.left.left = l; root.right.right = r; return; } helper(root.left,v,d,cur+1); helper(root.right,v,d,cur+1); }