当前位置:网站首页>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;
边栏推荐
- The sharp drop in electricity consumption in Guangdong shows that the substitution of high-tech industries for high-energy consumption industries has achieved preliminary results
- Activity的生命周期和启动模式详解
- Dataframe gets the number of words in the string
- Comment utiliser le langage MySQL pour les appareils de ligne et de ligne?
- Redis 分布式锁
- FPN network details
- China carbon disulfide industry research and investment strategy report (2022 Edition)
- Bugku's file contains
- Kali install Nessus
- SystemVerilog-结构体(二)
猜你喜欢
Activity的生命周期和启动模式详解
What is the effect of choosing game shield safely in the game industry?
How to restore the system of Sony laptop
MLPerf Training v2.0 榜单发布,在同等GPU配置下百度飞桨性能世界第一
数据库系统原理与应用教程(002)—— MySQL 安装与配置:MySQL 软件的卸载(windows 环境)
What is the digital transformation of manufacturing industry
怎麼用MySQL語言進行行列裝置?
Ring iron pronunciation, dynamic and noiseless, strong and brilliant, magic wave hifiair Bluetooth headset evaluation
Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!
数据库系统原理与应用教程(001)—— MySQL 安装与配置:MySQL 软件的安装(windows 环境)
随机推荐
Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
嗨 FUN 一夏,与 StarRocks 一起玩转 SQL Planner!
What is the digital transformation of manufacturing industry
数据库系统原理与应用教程(005)—— yum 离线安装 MySQL5.7(Linux 环境)
OJ questions related to complexity (leetcode, C language, complexity, vanishing numbers, rotating array)
[flask introduction series] cookies and session
MLPerf Training v2.0 榜单发布,在同等GPU配置下百度飞桨性能世界第一
AI college entrance examination volunteer filling: the gods of Dachang fight, and candidates pay to watch
Red team Chapter 10: ColdFusion the difficult process of deserializing WAF to exp to get the target
VMware 虚拟机启动时出现故障:VMware Workstation 与 Hyper-v 不兼容...
Submission lottery - light application server essay solicitation activity (may) award announcement
想做软件测试的女孩子看这里
Rhcsa Road
Research and investment strategy report of neutral protease industry in China (2022 Edition)
How does go use symmetric encryption?
Sweden announced its decision to exclude Huawei 5g equipment, but Huawei has successfully found a new way out
剑指 Offer II 015. 字符串中的所有变位词
单例模式的懒汉模式跟恶汉模式的区别
Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
Template engine velocity Foundation