234. Palindrome Linked List(回文链表)

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

题目要求:以 O(1) 的空间复杂度来求解。

切成两半,把后半段反转,然后比较两半是否相等。

 

时间复杂度:o(n)                  空间复杂度:o(1)

 

posted on 2019-03-19 22:48  shaer  阅读(116)  评论(0编辑  收藏  举报

导航