LeetCode 剑指 Offer II 027. 回文链表
文章目录
题目描述
LeetCode 剑指 Offer II 027. 回文链表
提示:
一、解题关键词
二、解题报告
1.思路分析
2.时间复杂度
3.代码示例
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public boolean isPalindrome(ListNode head) {
//奇数偶数讨论
if(null == head) return false;
List<Integer> list = new ArrayList<>();
while(head != null){
list.add(head.val);
head = head.next;
}
int left = 0,right = list.size() - 1;
while(left < right){
if(list.get(left) != list.get(right)){
return false;
}
left ++;
right --;
}
return true;
}
}
2.知识点
so easy 妈妈再也不用担心我的学习
总结
相同题目
234. 回文链表