The first loop put elements in linked list into a stack. the second loop will check if the stack matches linked list in transversed order (because the pop will provides the last element been pushed). If the linked list is not a palindrome then return False, otherwise return True.
The first loop put elements in linked list into a stack. the second loop will check if the stack matches linked list in transversed order (because the pop will provides the last element been pushed). If the linked list is not a palindrome then return False, otherwise return True.
C3EZ
4 months ago
2024-9-17 3:19:30
The best case complexity is O(n) where n is the length of linked list, and return false at first time run the second loop.
The worst case complexity is O(2n), or O(n)where n is the length of linked list, and finsihed the second loop.
The best case complexity is O(n) where n is the length of linked list, and return false at first time run the second loop.
The worst case complexity is O(2n), or O(n)where n is the length of linked list, and finsihed the second loop.
The first loop put elements in linked list into a stack. the second loop will check if the stack matches linked list in transversed order (because the pop will provides the last element been pushed). If the linked list is not a palindrome then return False, otherwise return True.
The best case complexity is O(n) where n is the length of linked list, and return false at first time run the second loop.
The worst case complexity is O(2n), or O(n)where n is the length of linked list, and finsihed the second loop.