Skip to content

Commit b44504d

Browse files
committed
add space time complexity
1 parent ecdcbc5 commit b44504d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

binary-trees/list-of-depths.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const LinkedList = require("../utils/LinkedList");
33
* Given a binary tree design an algorithm wich creates
44
* a linked list of all the nodes at each depth (e.g., if you
55
* have a tree with depth D, you'll have D linked lists).
6+
* Time O(n)
7+
* Space O(n)
68
*/
79

810
class Node {

utils/LinkedList.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class LinkedList {
2+
constructor(value) {
3+
this.value = value;
4+
this.next = null;
5+
}
6+
7+
add(value) {
8+
let currentNode = this;
9+
10+
while (currentNode !== null) {
11+
currentNode = currentNode.next;
12+
}
13+
currentNode.next = new LinkedList(value);
14+
}
15+
}
16+
17+
module.exports = LinkedList;

0 commit comments

Comments
 (0)