当前位置:网站首页>Determine whether the linked list is a palindrome linked list
Determine whether the linked list is a palindrome linked list
2022-07-01 16:47:00 【Fried tomatoes with duck eggs】
The first step is to put the values of the linked list in the array list , Then through the double pointer to determine whether it is a palindrome linked list , A pointer starts from scratch , The other pointer starts at the end , Traverse in turn , If the values encountered are different, return directly false, If the value is the same, continue to traverse , Until the two indexes meet .
First step :
List<Integer> arr=new ArrayList<Integer>();
ListNode currentNode=head;
Boolean flag=true;
while (currentNode!=null){
arr.add(currentNode.val);
currentNode=currentNode.next;
}The second step :
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;边栏推荐
- Stegano in the world of attack and defense
- China's intelligent transportation construction from the perspective of "one hour life circle" in Dawan District
- [jetsonnano] [tutorial] [introductory series] [III] build tensorflow environment
- Sqlserver query: when a.id is the same as b.id, and the A.P corresponding to a.id cannot be found in the B.P corresponding to b.id, the a.id and A.P will be displayed
- Is the programmer's career really short?
- sql刷题1050. 合作过至少三次的演员和导演
- Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
- 模板引擎Velocity 基础
- 用手机在同花顺上开户靠谱吗?这样有没有什么安全隐患
- Installation and use of sqoop
猜你喜欢

Analysis of PostgreSQL storage structure

PostgreSQL 存储结构浅析

China's intelligent transportation construction from the perspective of "one hour life circle" in Dawan District

PR basic clip operation / video export operation

Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist

Redis 分布式锁

数据库系统原理与应用教程(001)—— MySQL 安装与配置:MySQL 软件的安装(windows 环境)

模板引擎Velocity 基础

游戏行业安全选择游戏盾,效果怎么样?

Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
随机推荐
Leetcode 216 combined summation III -- backtracking method
Red team Chapter 8: blind guess the difficult utilization process of the package to upload vulnerabilities
Introduction to software engineering - Chapter 6 - detailed design
Principle of SSM framework
剑指 Offer II 015. 字符串中的所有变位词
Bugku's file contains
全面看待企业数字化转型的价值
怎麼用MySQL語言進行行列裝置?
[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
P2893 [USACO08FEB] Making the Grade G(dp&优先队列)
How to cancel automatic search and install device drivers for laptops
Advantages, values and risks of chain games compared with traditional games
Comment utiliser le langage MySQL pour les appareils de ligne et de ligne?
Redis 分布式锁
免费抽奖 | 《阿巴豆》探索未来系列盲盒数字版权作品全网首发!
China nylon 11 industry research and future forecast report (2022 Edition)
Flux d'entrées / sorties et opérations de fichiers en langage C
Zabbix2.2 monitoring system and application log monitoring alarm
程序员职业生涯真的很短吗?
Origin2018 installation and use (sorting)