We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f8df6d0 commit 530d1b6Copy full SHA for 530d1b6
SinglyLinkedList.js
@@ -100,6 +100,22 @@ class SinglyLinkedList {
100
return true;
101
}
102
103
+
104
+ remove(index) {
105
+ if (index < 0 || index >= this.length) return;
106
107
+ if (index === 0) return this.shift();
108
+ else if (index === this.length - 1) this.pop();
109
+ else {
110
+ let left = this.get(index - 1);
111
+ let removed = left.next;
112
+ let right = removed.next;
113
114
+ left.next = right;
115
+ this.length--;
116
+ return removed;
117
+ }
118
119
120
121
let list = new SinglyLinkedList();
0 commit comments