@@ -0,0 +1,1132 @@
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0Apublic class _0623AddOneRowToTree %7B%0A  public TreeNode addOneRow(TreeNode root, int val, int depth) %7B%0A    if (depth == 1) %7B%0A      TreeNode node = new TreeNode(val, root, null);%0A      return node;%0A    %7D%0A    List%3CTreeNode%3E nodes = new ArrayList%3C%3E();%0A    nodes.add(root);%0A    int d = 1;%0A    while (d %3C depth - 1) %7B%0A      List%3CTreeNode%3E newNodes = new ArrayList%3C%3E();%0A      for (TreeNode node : nodes) %7B%0A        if (node.left != null) %7B%0A          newNodes.add(node.left);%0A        %7D%0A        if (node.right != null) %7B%0A          newNodes.add(node.right);%0A        %7D%0A      %7D%0A      nodes = newNodes;%0A      d++;%0A    %7D%0A    for (TreeNode node : nodes) %7B%0A      node.left = new TreeNode(val, node.left, null);%0A      node.right = new TreeNode(val, null, node.right);%0A    %7D%0A    return root;%0A  %7D%0A%0A  public class TreeNode %7B%0A      int val;%0A      TreeNode left;%0A      TreeNode right;%0A      TreeNode() %7B%7D%0A      TreeNode(int val) %7B this.val = val; %7D%0A      TreeNode(int val, TreeNode left, TreeNode right) %7B%0A          this.val = val;%0A          this.left = left;%0A          this.right = right;%0A      %7D%0A  %7D%0A%7D%0A

Add _0623AddOneRowToTree