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
var CBTInserter = function (root) {20
CBTInserter.prototype.insert = function (val) {23
while (queue.length) {24
let updatedQueue = [];25
while (queue.length) {26
let node = queue.shift();28
node.left = new TreeNode(val);30
} else updatedQueue.push(node.left);32
node.right = new TreeNode(val);34
} else updatedQueue.push(node.right);43
CBTInserter.prototype.get_root = function () {48
* Your CBTInserter object will be instantiated and called as such:49
* var obj = new CBTInserter(root)50
* var param_1 = obj.insert(val)51
* var param_2 = obj.get_root()