当前位置:网站首页>判断链表是否是回文链表
判断链表是否是回文链表
2022-07-01 16:26:00 【鸭蛋炒西红柿】
第一步先将链表的值放在数组列表里,然后通过双指针来判断是否是回文链表,一个指针从头开始,另一个指针从尾开始,依次遍历,如果遇到的值不一样直接返回false,值一样则继续遍历,直到两个索引相遇。
第一步:
List<Integer> arr=new ArrayList<Integer>();
ListNode currentNode=head;
Boolean flag=true;
while (currentNode!=null){
arr.add(currentNode.val);
currentNode=currentNode.next;
}
第二步:
int front=0;
int back=arr.size()-1;
while (front<back){
if (!arr.get(front).equals(arr.get(back))){
flag=false;
}
front++;
back--;
}
return flag;
边栏推荐
- P2592 [zjoi2008] birthday party (DP)
- Advantages, values and risks of chain games compared with traditional games
- Rhcsa Road
- Authentication processing in interface testing framework
- Stonedb is building blocks for domestic databases, and the integrated real-time HTAP database based on MySQL is officially open source!
- C語言輸入/輸出流和文件操作
- 接口测试框架中的鉴权处理
- Principle of SSM framework
- 怎麼用MySQL語言進行行列裝置?
- StoneDB 为国产数据库添砖加瓦,基于 MySQL 的一体化实时 HTAP 数据库正式开源!
猜你喜欢
VMware virtual machine failed during startup: VMware Workstation is incompatible with hyper-v
StoneDB 为国产数据库添砖加瓦,基于 MySQL 的一体化实时 HTAP 数据库正式开源!
Are you still using charged document management tools? I have a better choice! Completely free
How to restore the system of Sony laptop
Comprehensively view the value of enterprise digital transformation
Sweden announced its decision to exclude Huawei 5g equipment, but Huawei has successfully found a new way out
Germany if was crowned with many awards. How strong is this pair of headphones? In depth evaluation of yinpo GTW 270 hybrid
独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
Authentication processing in interface testing framework
Principle of motion capture system
随机推荐
How to repair the laptop that cannot connect to the wireless network
[JetsonNano] [教程] [入门系列] [三] 搭建TensorFlow环境
Tutorial on principles and applications of database system (004) -- MySQL installation and configuration: resetting MySQL login password (Windows Environment)
Detailed explanation of activity life cycle and startup mode
Is it reliable to open an account on flush with mobile phones? Is there any potential safety hazard
Bugku's file contains
sql刷题627. 变更性别
Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers
I'm a senior test engineer who has been outsourced by Alibaba and now has an annual salary of 40w+. My two-year career changing experience is sad
Are you still using charged document management tools? I have a better choice! Completely free
芯片供应转向过剩,中国芯片日产增加至10亿,国外芯片将更难受
【Kotlin】高阶函数介绍
Tutorial on the principle and application of database system (002) -- MySQL installation and configuration: MySQL software uninstallation (Windows Environment)
模板引擎Velocity 基础
Défaillance lors du démarrage de la machine virtuelle VMware: le poste de travail VMware n'est pas compatible avec hyper - V...
Problems encountered in IM instant messaging development to maintain heartbeat
制造业数字化转型究竟是什么
[nodemon] app crashed - waiting for file changes before starting... resolvent
[kotlin] Introduction to higher-order functions
[SQL statement] Why do you select two Shanghai and query different counts here? I want it to become a Shanghai, and count only displays a sum