Problem
Given a singly linked list, determine if it is a palindrome.
Examples
1 | Input: 1->2 |
1 | Input: 1->2->2->1 |
Solution1
Method: Brute Force
Time Complexity: O(n)
Space Complexity: O(n)
1 | # Definition for singly-linked list. |
Solution2
Method:
Time Complexity: O(n)
Space Complexity: O(1)
1 | # Definition for singly-linked list. |
or-time-O(1)-space)
1 | def isPalindrome(self, head): |