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); }) }}
3.75
4
function height(root) { function dfs(node) { if(node === null) return 0; return Math.max(dfs(node.left), dfs(node.right)) + 1; } dfs(root);}
Thank you!
4
0
3.56
9
let arr = [1, 2, 3, 4, 5];for(let i = 0; i < arr.length; i++){ console.log(arr[i]);}
Thank you!
9
0
0
0
function countNodes(root) { function dfs(node) { if(node === null) return 0; return dfs(node.left) + dfs(node.right) + 1; } dfs(root);}
Thank you!
0
0
Are there any code examples left?
New code examples in category Shell/Bash
-
Shell/Bash 2022-03-27 22:30:33 wise highlight ubuntu
-
Shell/Bash 2022-03-27 22:25:19 how to send a pull request in git
-
Shell/Bash 2022-03-27 21:55:06 how to open terminal in sublime text ubuntu
-
Shell/Bash 2022-03-27 21:25:19 how to switch branch
-
Shell/Bash 2022-03-27 21:20:25 python
-
Shell/Bash 2022-03-27 21:20:04 set user as admin gitlab
-
Shell/Bash 2022-03-27 21:10:09 apache2 mod_jk proxy to tomcat connector
-
Shell/Bash 2022-03-27 20:35:12 chown
-
Shell/Bash 2022-03-27 20:15:08 awk last match