回文链表
来源:互联网 发布:mac安装homebrew失败 编辑:程序博客网 时间:2024/06/05 02:05
题目描述
请编写一个函数,检查链表是否为回文。
给定一个链表ListNode* pHead,请返回一个bool,代表链表是否为回文。
测试样例:
{1,2,3,2,1}
返回:true
{1,2,3,2,3}
返回:false
import java.util.*;/*public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class Palindrome { public boolean isPalindrome(ListNode pHead) { // write code here if(pHead == null) return false; ListNode p = pHead; ListNode head = new ListNode(0); while(p != null){ ListNode q = new ListNode(p.val); p = p.next; q.next = head.next; head.next = q; } head = head.next; while(head != null){ if(head.val != pHead.val) return false; head = head.next; pHead = pHead.next; } return true; }}
0 0
- 字符串回文判断, 链表回文判断
- 链表回文判断
- 回文链表
- 回文链表(Java)
- 回文链表
- 回文链表
- 回文链表
- 判断回文链表
- 回文链表
- LintCode:回文链表
- 回文链表
- 回文链表
- 回文链表
- 回文链表
- 回文链表
- 链表回文
- LintCode:回文链表
- lintcode,回文链表
- 进程、线程
- 分分钟搞定自定义控件之组合控件--自定义View入门篇
- 也学习Java/JVM/GC (三)
- hdu 5821 2016 Multi-University Training Contest 8 Ball 解题报告
- 常见的css的一些注意点
- 回文链表
- C++远征之起航篇知识点
- 51nod 1105 第K大的数(二分)
- schema文件相关知识
- GridLayout学习使用
- js对Date类和String的扩展
- 一文读懂机器学习,大数据/自然语言处理/算法全有了……
- 六,UITabBarController
- UE4 的 C++ 开发体验