mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 15:11:16 +08:00
Twice defined (#124)
* Twice defined Parameter 'deletedTail' were defined twice. * Update LinkedList.js * Update LinkedList.js
This commit is contained in:
parent
6e897a0a7a
commit
5105898aa7
@ -127,18 +127,14 @@ export default class LinkedList {
|
|||||||
* @return {LinkedListNode}
|
* @return {LinkedListNode}
|
||||||
*/
|
*/
|
||||||
deleteTail() {
|
deleteTail() {
|
||||||
|
const deletedTail = this.tail;
|
||||||
if (this.head === this.tail) {
|
if (this.head === this.tail) {
|
||||||
// There is only one node in linked list.
|
// There is only one node in linked list.
|
||||||
const deletedTail = this.tail;
|
|
||||||
this.head = null;
|
this.head = null;
|
||||||
this.tail = null;
|
this.tail = null;
|
||||||
|
|
||||||
return deletedTail;
|
return deletedTail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are many nodes in linked list...
|
|
||||||
const deletedTail = this.tail;
|
|
||||||
|
|
||||||
// Rewind to the last node and delete "next" link for the node before the last one.
|
// Rewind to the last node and delete "next" link for the node before the last one.
|
||||||
let currentNode = this.head;
|
let currentNode = this.head;
|
||||||
while (currentNode.next) {
|
while (currentNode.next) {
|
||||||
|
Loading…
Reference in New Issue
Block a user