当前位置:网站首页>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;边栏推荐
- 今天14:00 | 港大、北航、耶鲁、清华、加大等15位ICLR一作讲者精彩继续!
- Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!
- 挖财学堂班主任给的证券账户安全吗?能开户吗?
- Tutorial on the principle and application of database system (001) -- MySQL installation and configuration: installation of MySQL software (Windows Environment)
- Go 语言怎么使用对称加密?
- How to solve the keyboard key failure of notebook computer
- Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
- 剑指 Offer II 015. 字符串中的所有变位词
- Buuctf gold III
- [live broadcast appointment] database obcp certification comprehensive upgrade open class
猜你喜欢

怎麼用MySQL語言進行行列裝置?

VMware 虛擬機啟動時出現故障:VMware Workstation 與 Hyper-v 不兼容...

Redis6.0 新功能

数据库系统原理与应用教程(002)—— MySQL 安装与配置:MySQL 软件的卸载(windows 环境)
![[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](/img/a4/58b942d1389834069e9a6ec9f8ee0a.png)
[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

广东用电量大跌,说明高新技术产业替代高能耗产业已取得初步成果

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

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

How to use MySQL language for row and column devices?

VMware 虚拟机启动时出现故障:VMware Workstation 与 Hyper-v 不兼容...
随机推荐
虚拟串口模拟器和串口调试助手使用教程「建议收藏」
数据库系统原理与应用教程(002)—— MySQL 安装与配置:MySQL 软件的卸载(windows 环境)
Leetcode 216 combined summation III -- backtracking method
sql刷题586. 订单最多的客户
How does go use symmetric encryption?
接口测试框架中的鉴权处理
Go 语言怎么使用对称加密?
How to restore the system with one click on Lenovo laptop
挖财学堂班主任给的证券账户安全吗?能开户吗?
Origin2018安装与使用(整理中)
Apple's self-developed baseband chip failed again, which shows Huawei Hisilicon's technological leadership
FPN网络详解
vim用户自动命令示例
How to use phpipam to manage IP addresses and subnets
数据库系统原理与应用教程(004)—— MySQL 安装与配置:重置 MySQL 登录密码(windows 环境)
C語言輸入/輸出流和文件操作
【Hot100】19. Delete the penultimate node of the linked list
C language input / output stream and file operation
嗨 FUN 一夏,与 StarRocks 一起玩转 SQL Planner!
Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world