Given a singly linked list, determine if it is a palindrome. 给出一个单链表,确定它是否是回文。
Example 1:
Input: 1->2
Output: false
Example 2:
Input: 1->2->2->1 Output: true
Follow up:
Could you do it in O(n) time and O(1) space?
-
思路 把链表转化成数组,然后分别从数组的头部和尾部开始比较
-
用时 30分钟