From f6557350278c0f55905695edecca9ee47b8a11ab Mon Sep 17 00:00:00 2001 From: sammychien Date: Fri, 10 Jul 2020 15:33:43 -0500 Subject: [PATCH] getLast uses tail node instead of traversing list --- DoublyLinkedList/DoublyLinkedList.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/DoublyLinkedList/DoublyLinkedList.go b/DoublyLinkedList/DoublyLinkedList.go index e6e39f9..0ad3085 100644 --- a/DoublyLinkedList/DoublyLinkedList.go +++ b/DoublyLinkedList/DoublyLinkedList.go @@ -113,11 +113,7 @@ func (list *LinkedList) GetLast() (int, bool) { if list.head == nil { return 0, false } - current := list.head - for current.next != nil { - current = current.next - } - return current.data, true + return list.tail.data, true } func (list *LinkedList) GetSize() int {