Skip to content

Commit 85288c1

Browse files
committed
Update removeValue
1 parent ad43ee7 commit 85288c1

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Diff for: linked-list.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ class LinkedList {
8787
return null;
8888
}
8989
if (this.head.value === value) {
90-
if (!this.head.next) {
91-
this.head = null;
92-
} else {
93-
this.head = this.head.next;
94-
}
90+
this.head = this.head.next;
9591
this.size--;
9692
return value;
9793
} else {
@@ -100,7 +96,8 @@ class LinkedList {
10096
prev = prev.next;
10197
}
10298
if (prev.next) {
103-
prev.next = prev.next.next;
99+
removedNode = prev.next;
100+
prev.next = removedNode.next;
104101
this.size--;
105102
return value;
106103
}

0 commit comments

Comments
 (0)