当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢
IDEA Gradle 常遇问题(二)(持续更新)
FFmpeg multimedia file processing (implementation of ffmpeg operation directory and list)
Explanation of RTSP protocol
gin的中间件和路由分组
Clock frequency and baud rate count for serial communication in FPGA
[极客大挑战 2019]Upload
GIN中GET POST PUT DELETE请求
某高校的R语言数据分析期末作业
FPGA中串口通信的时钟频率和波特率计数
gin's middleware and routing grouping
随机推荐
GIN初探,环境安装
剑指 Offer 43. 1~n 整数中 1 出现的次数(递归、数学)
为什么文字不贴合边
FFMPEG多媒体文件处理(ffmpeg文件的删除与重命名)
【奖励公示】第23期 2022年7月奖励名单公示:社区明星评选 | 新人奖 | 博客同步 | 推荐奖
万物皆可柯里化的 Ramda.js
glibc memory management model freeing C library memory cache
GIN Bind模式获取参数和表单验证
驻波比计算方法
eslint语法规则报错
read stream special attention
Professor Chen Qiang the machine learning and R application course chapter 18 assignments
【NVIDIA】Tesla V100安装NVIDIA-Driver驱动程序适配CUDA-Toolkit-11.6
WSA工具箱安装应用商店提示无法工作怎么解决?
蓝桥杯线上模拟赛——Flex 经典骰子布局
微服务+微信小程序实现社区服务
read stream 特别注意
telnet+ftp to control and upgrade the device
Time series analysis course lab report
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 16 Assignment