alexeibs
0
Q:

lintcode

class BST {  constructor() {    this.root = null;  }  addNode(val) {    function dfs(node) {      if(node === null) {        return new TreeNode(val);      }      if(val >= node.val) {        node.right = dfs(node.right);      } else {        node.left = dfs(node.left);      }      return node;    }    this.root = dfs(this.root);  }addNodes(arr) {    let tree = this;    arr.forEach(val => {      tree.addNode(val);    })  }}
0
let arr = [1, 2, 3, 4, 5];for(let i = 0; i < arr.length; i++){  console.log(arr[i]);}
0
function countNodes(root) {  function dfs(node) {    if(node === null) return 0;    return dfs(node.left) + dfs(node.right) + 1;  }  dfs(root);}
0
function height(root) {  function dfs(node) {    if(node === null) return 0;    return Math.max(dfs(node.left), dfs(node.right)) + 1;  }  dfs(root);}
0

New to Communities?

Join the community