# 234. Palindrome Linked List 原

初雪之音

Given a singly linked list, determine if it is a palindrome.

Could you do it in O(n) time and O(1) space?

``````/**
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) { val = x; }
* }
*/
public class Solution {
boolean result = true;

while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
}
if (fast != null) {
slow = slow.next;
}
slow = reverse(slow);
while (slow != null) {
if (fast.val != slow.val) {
result = false;
break;
}
fast = fast.next;
slow = slow.next;
}
}

return result;
}

ListNode result = null;

ListNode pre = null;
}
result = pre;

return result;
}
}``````

### 初雪之音

234. Palindrome Linked List - LeetCode

Question 234. Palindrome Linked List Solution 题目大意：给一个链表，判断是该链表中的元素组成的串是否回文 思路：遍历链表添加到一个list中，再遍历list的一半判断对称元素是否相等，注...

yysue
07/10
0
0
LeetCode目录。

Leafage_M
2017/11/21
0
0

2015/12/18
196
0
LeetCode 234. Palindrome Linked List (回文链表)

dby_freedom
12/04
0
0

Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2Output: false Example 2: Input: 1->2->2->1Output: true Follow up: Could you do it in O(n) time......

woshixin

0
0

6分钟前
0
0
php分割二级域名做跳转处理方法

Mr_Azaz
8分钟前
0
0

3
0
esxi 更换ssl证书

bboysoulcn

1
0
PLC编程入门：梯形图

1
0