function TreeNode(val, left, right) {
this.val = (val === undefined ? 0 : val)
this.left = (left === undefined ? null : left)
this.right = (right === undefined ? null : right)
}
var insertIntoBST = function (root, val) {
let newNode = new TreeNode(val)
if(!root) {
root = newNode
return root
}
let cur = root
while (true) {
if (val < cur.val) {
if (cur.left === null) {
cur.left = newNode
break
}
cur = cur.left
} else {
if (cur.right === null) {
cur.right = newNode
break
}
cur = cur.right
}
}
return root
};