当前位置:网站首页>NC96 判断一个链表是否为回文结构
NC96 判断一个链表是否为回文结构
2022-08-09 13:02:00 【syc596】
NC96 判断一个链表是否为回文结构
判断一个链表是否为回文结构_牛客题霸_牛客网 (nowcoder.com)
import java.util.*;
public class Solution {
public ListNode reverse(ListNode head){
ListNode prev=null;
ListNode cur=head;
while(cur!=null){
ListNode next=cur.next;
cur.next=prev;
prev=cur;
cur=next;
}
return prev;
}
public boolean isPail (ListNode head) {
if(head==null){
return true;
}
ListNode slow=head;
ListNode fast=head;
while(fast!=null&&fast.next!=null){
slow=slow.next;
fast=fast.next.next;
}
slow=reverse(slow);
while(slow!=null){
if(slow.val!=head.val){
return false;
}
slow=slow.next;
head=head.next;
}
return true;
}
}
边栏推荐
- [极客大挑战 2019]Upload
- How to reduce the size of desktop icons after the computer is reinstalled
- 搭建大型分布式服务(二)搭建会员服务
- 面试攻略系列(三)-- 高级开发工程师面试问些啥?
- 5G China unicom 直放站 网管协议 实时性要求
- [FPGA Tutorial Case 48] Image Case 8 - Realization of Converting RGB Image to HSV Image Based on FPGA, Assisted Verification by MATLAB
- 陈强教授《机器学习及R应用》课程 第十八章作业
- GET POST PUT DELETE request in GIN
- Jenkins API groovy calling practice: Jenkins Core Api & Job DSL to create a project
- Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres
猜你喜欢
FFmpeg多媒体文件处理(ffmpeg处理流数据的基本概念)
eslint语法规则报错
The sword refers to the offer, cuts the rope 2
5G China unicom AP:B SMS ASCII Transcoding Requirements
puzzle(016.5)逻辑电路
IDEA Gradle 常遇问题(二)(持续更新)
gin的中间件和路由分组
Uni - app - uview Swiper shuffling figure component, click on the links to jump (click to get the item after the row data, remove data operation)
5G China unicom 一般性异常处理
搭建大型分布式服务(二)搭建会员服务
随机推荐
FPGA-近日工作总结
npm install失败
基于 R 语言的判别分析介绍与实践 LDA和QDA
GET POST PUT DELETE request in GIN
行程和用户[阅读理解法]
[FPGA Tutorial Case 48] Image Case 8 - Realization of Converting RGB Image to HSV Image Based on FPGA, Assisted Verification by MATLAB
FFmpeg multimedia file processing (FFMPEG logging system)
FFMPEG multimedia file processing (deletion and renaming of ffmpeg files)
Q_08 更多信息
Unicom network management protocol block diagram
jenkins api create custom pipeline
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 14 Assignment
telnet+ftp to control and upgrade the device
How to solve the 0x80070005 error when the computer is reinstalled and the system is restored
gin's middleware and routing grouping
WSA工具箱安装应用商店提示无法工作怎么解决?
ARM board adds routing function
Anta and Huawei Sports Health jointly verify the champion running shoes and lead Chinese sports with innovation
IDEA Gradle 常遇问题(一)
为什么文字不贴合边