linq leetcode code example

Example 1: 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);    })  }}

Example 2: lintcode

function height(root) {  function dfs(node) {    if(node === null) return 0;    return Math.max(dfs(node.left), dfs(node.right)) + 1;  }  dfs(root);}

Tags:

Misc Example