当前位置:网站首页>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;
}
}边栏推荐
猜你喜欢

Jenkins API groovy calling practice: Jenkins Core Api & Job DSL to create a project

GIN Bind mode to get parameters and form validation

5G China unicom 一般性异常处理

快来扔鸡蛋。

gin的中间件和路由分组

How to solve the 0x80070005 error when the computer is reinstalled and the system is restored

GIN a preliminary study, the environment is installed

七夕力扣刷不停,343. 整数拆分(剑指 Offer 14- I. 剪绳子、剑指 Offer 14- II. 剪绳子 II)

kustomize入门示例及基本语法使用说明

eslint语法规则报错
随机推荐
error Trailing spaces not allowed no-trailing-spaces 9:14 error Unexpected trailing comma
jenkins api create custom pipeline
IDEA Gradle 常遇问题(一)
Unity3d_API_Gyroscope 陀螺仪的接口
昇腾AI开发者创享日南京站!一起CANN机器狗+AI机械臂实现硬核智慧救援!燃爆现场~
剑指 Offer 56 - II. 数组中数字出现的次数 II(位运算)
陈强教授《机器学习及R应用》课程 第十三章作业
GIN a preliminary study, the environment is installed
ftplib+ tqdm 上传下载进度条
自己做了个nodejs+epxress+mysql的小项目,怎么才能让别人通过互联网访问呢?
[MRCTF2020]套娃-1
ArcEngine(八) 选择要素并高亮显示
The sword refers to Offer 56 - II. Number of occurrences of a number in an array II (bit operation)
Sandbox中的进程/线程相关-1
javscript基础易错点集合
The sword refers to Offer 57 - II. and is a continuous positive sequence of s (sliding window)
七夕力扣刷不停,343. 整数拆分(剑指 Offer 14- I. 剪绳子、剑指 Offer 14- II. 剪绳子 II)
群组行动控制--自动队列化实现策略
Professor Chen Qiang the machine learning and R application course chapter 18 assignments
5G 联通网管设计思路