var CONFIG = {"hostname":"nicksxs.me","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
</script>
<metaname="description"content="Given a singly linked list, determine if it is a palindrome. Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueFollow up:Could you do it in O(n) time and O(1) spac">
<metaname="description"content="题目介绍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">
<metaproperty="og:description"content="Given a singly linked list, determine if it is a palindrome. Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueFollow up:Could you do it in O(n) time and O(1) spac">
<metaproperty="og:description"content="题目介绍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">
<h2id="题目介绍"><ahref="#题目介绍"class="headerlink"title="题目介绍"></a>题目介绍</h2><p>Given a singly linked list, determine if it is a palindrome.<br>给定一个单向链表,判断是否是回文链表</p>
<h3id="例一-Example-1"><ahref="#例一-Example-1"class="headerlink"title="例一 Example 1:"></a>例一 Example 1:</h3><p>Input: 1->2<br>Output: false</p>
<h3id="例二-Example-2"><ahref="#例二-Example-2"class="headerlink"title="例二 Example 2:"></a>例二 Example 2:</h3><p>Input: 1->2->2->1<br>Output: true</p>
<h3id="挑战下自己"><ahref="#挑战下自己"class="headerlink"title="挑战下自己"></a>挑战下自己</h3><p>Follow up:<br>Could you do it in O(n) time and O(1) space?</p>
<h2id="简要分析"><ahref="#简要分析"class="headerlink"title="简要分析"></a>简要分析</h2><p>首先这是个单向链表,如果是双向的就可以一个从头到尾,一个从尾到头,显然那样就没啥意思了,然后想过要不找到中点,然后用一个栈,把前一半塞进栈里,但是这种其实也比较麻烦,比如长度是奇偶数,然后如何找到中点,这倒是可以借助于双指针,还是比较麻烦,再想一想,回文链表,就跟最开始的一样,链表只有单向的,我用个栈不就可以逆向了么,先把链表整个塞进栈里,然后在一个个 pop 出来跟链表从头开始比较,全对上了就是回文了</p>
<h2 id="题目介绍"><a href="#题目介绍" class="headerlink" title="题目介绍"></a>题目介绍</h2><p>Given a singly linked list, determine if it is a
<h2id="题目介绍"><ahref="#题目介绍"class="headerlink"title="题目介绍"></a>题目介绍</h2><p>Given a singly linked list, determine if it is a palindrome.<br>给定一个单向链表,判断是否是回文链表</p>
<h3id="例一-Example-1"><ahref="#例一-Example-1"class="headerlink"title="例一 Example 1:"></a>例一 Example 1:</h3><p>Input: 1->2<br>Output: false</p>
<h3id="例二-Example-2"><ahref="#例二-Example-2"class="headerlink"title="例二 Example 2:"></a>例二 Example 2:</h3><p>Input: 1->2->2->1<br>Output: true</p>
<h3id="挑战下自己"><ahref="#挑战下自己"class="headerlink"title="挑战下自己"></a>挑战下自己</h3><p>Follow up:<br>Could you do it in O(n) time and O(1) space?</p>
<h2id="简要分析"><ahref="#简要分析"class="headerlink"title="简要分析"></a>简要分析</h2><p>首先这是个单向链表,如果是双向的就可以一个从头到尾,一个从尾到头,显然那样就没啥意思了,然后想过要不找到中点,然后用一个栈,把前一半塞进栈里,但是这种其实也比较麻烦,比如长度是奇偶数,然后如何找到中点,这倒是可以借助于双指针,还是比较麻烦,再想一想,回文链表,就跟最开始的一样,链表只有单向的,我用个栈不就可以逆向了么,先把链表整个塞进栈里,然后在一个个 pop 出来跟链表从头开始比较,全对上了就是回文了</p>