Given a singly linked list, determine if it is a palindrome.
Follow up:
Could you do it in O(n) time and O(1) space?
把前一半反转一下,然后用两个指针,将一个移到中间后,开始逐个看两个指针上的数据是否相等
1 | /** |
Given a singly linked list, determine if it is a palindrome.
Follow up:
Could you do it in O(n) time and O(1) space?
1 | /** |