2
* Definition for a binary tree node.3
* function TreeNode(val, left, right) {4
* this.val = (val===undefined ? 0 : val)5
* this.left = (left===undefined ? null : left)6
* this.right = (right===undefined ? null : right)10
* @param {TreeNode} root12
* @param {number} depth15
var addOneRow = function (root, val, depth) {16
if (depth === 1) return new TreeNode(val, root);18
const refactor = (node = root, currentDep = 1) => {20
if (currentDep === depth - 1) {21
const { left, right } = node;22
node.left = new TreeNode(val, left);23
node.right = new TreeNode(val, null, right);25
refactor(node.left, currentDep + 1);26
refactor(node.right, currentDep + 1);