We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ecdcbc5 commit b44504dCopy full SHA for b44504d
binary-trees/list-of-depths.js
@@ -3,6 +3,8 @@ const LinkedList = require("../utils/LinkedList");
3
* Given a binary tree design an algorithm wich creates
4
* a linked list of all the nodes at each depth (e.g., if you
5
* have a tree with depth D, you'll have D linked lists).
6
+ * Time O(n)
7
+ * Space O(n)
8
*/
9
10
class Node {
utils/LinkedList.js
@@ -0,0 +1,17 @@
1
+class LinkedList {
2
+ constructor(value) {
+ this.value = value;
+ this.next = null;
+ }
+
+ add(value) {
+ let currentNode = this;
+ while (currentNode !== null) {
11
+ currentNode = currentNode.next;
12
13
+ currentNode.next = new LinkedList(value);
14
15
+}
16
17
+module.exports = LinkedList;
0 commit comments