-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhackerRankCondList.js
47 lines (39 loc) · 934 Bytes
/
hackerRankCondList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// UPER
// U
// TAKE A ARRAY(SL-LIST) AND REMOVE DUPLICATES AND RETURN THE ARRAY(SL-LIST)
// EX: INPUT [3, 4, 3, 6] OUTPUT [3, 4, 6]
// ?
// IF TAKING INPUT OF AN INT, WHERE DOES ARRAY COME FROM?
// P
// PUT ALL VALUES FROM ARRAY INTO A DUPLICATE ARRAY
// CHECK VALUE OF EACH NODE, PUT IN ARRAY,
// IF VALUE ALREADY IN ARRAY DON'T ADD
// RETURN NEW ARRAY
const SinglyLinkedListNode = class {
constructor(nodeData) {
// DATA IN AN INTEGER
this.data = nodeData
// NULL IF AT TAIL
this.next = null
}
}
// SHOULDN'T NEED TO MODIFY THESE 2
const SinglyLinkedList = class {
constructor() {
this.head = null
this.tail = null
}
insertNode(nodeData) {
const node = new SinglyLinkedListNode(nodeData)
if (this.head == null) {
this.head = node
} else {
this.tail.next = node
}
this.tail = node
}
}
// CODE ALL HERE
function condense(head) {
// Write your code here
}