当前位置:网站首页>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;边栏推荐
- Research and investment strategy report of neutral protease industry in China (2022 Edition)
- C语言输入/输出流和文件操作
- Défaillance lors du démarrage de la machine virtuelle VMware: le poste de travail VMware n'est pas compatible avec hyper - V...
- How to optimize repeated if err in go language= Nil template code?
- Submission lottery - light application server essay solicitation activity (may) award announcement
- PostgreSQL 存储结构浅析
- Rhcsa Road
- 数据库系统原理与应用教程(001)—— MySQL 安装与配置:MySQL 软件的安装(windows 环境)
- Building blocks for domestic databases, stonedb integrated real-time HTAP database is officially open source!
- Kali install Nessus
猜你喜欢

Stegano in the world of attack and defense

芯片供应转向过剩,中国芯片日产增加至10亿,国外芯片将更难受

Tutorial on principles and applications of database system (004) -- MySQL installation and configuration: resetting MySQL login password (Windows Environment)

What is the digital transformation of manufacturing industry

Internet News: "20220222" get together to get licenses; Many products of Jimi have been affirmed by consumers; Starbucks was fined for using expired ingredients in two stores

Stonedb is building blocks for domestic databases, and the integrated real-time HTAP database based on MySQL is officially open source!

How to solve the keyboard key failure of notebook computer

模板引擎Velocity 基礎

The supply of chips has turned to excess, and the daily output of Chinese chips has increased to 1billion, which will make it more difficult for foreign chips

How to use F1 to F12 correctly on laptop keyboard
随机推荐
[flask introduction series] cookies and session
【Hot100】17. Letter combination of telephone number
博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
Tutorial on the principle and application of database system (003) -- MySQL installation and configuration: manually configure MySQL (Windows Environment)
Apple's self-developed baseband chip failed again, which shows Huawei Hisilicon's technological leadership
Rhcsa Road
【PyG】文档总结以及项目经验(持续更新
How to optimize repeated if err in go language= Nil template code?
数据库系统原理与应用教程(001)—— MySQL 安装与配置:MySQL 软件的安装(windows 环境)
How to use MySQL language for row and column devices?
FPN网络详解
Flux d'entrées / sorties et opérations de fichiers en langage C
VMware 虚拟机启动时出现故障:VMware Workstation 与 Hyper-v 不兼容...
China nylon 11 industry research and future forecast report (2022 Edition)
Rhcsa Road
P2592 [ZJOI2008]生日聚会(dp)
Why is the pkg/errors tripartite library more recommended for go language error handling?
Comprehensively view the value of enterprise digital transformation
Analysis of PostgreSQL storage structure
Endeavouros mobile hard disk installation