当前位置:网站首页>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;边栏推荐
- Kali install Nessus
- Go language source level debugger delve
- 全面看待企业数字化转型的价值
- UML旅游管理系统「建议收藏」
- 数据库系统原理与应用教程(004)—— MySQL 安装与配置:重置 MySQL 登录密码(windows 环境)
- Redis6.0 新功能
- Why is the pkg/errors tripartite library more recommended for go language error handling?
- Tutorial on principles and applications of database system (006) -- compiling and installing MySQL 5.7 (Linux Environment)
- Comprehensively view the value of enterprise digital transformation
- C語言輸入/輸出流和文件操作
猜你喜欢

Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers

Guide for high-end programmers to fish at work

独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作

【PyG】文档总结以及项目经验(持续更新

Buuctf gold III

How to solve the problem that the battery icon of notebook computer does not display

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

How to maintain the laptop battery

Germany if was crowned with many awards. How strong is this pair of headphones? In depth evaluation of yinpo GTW 270 hybrid

SQL question brushing 627 Change gender
随机推荐
剑指 Offer II 015. 字符串中的所有变位词
判断链表是否是回文链表
模板引擎Velocity 基礎
全面看待企业数字化转型的价值
Research and investment strategy report of neutral protease industry in China (2022 Edition)
【Hot100】19. Delete the penultimate node of the linked list
你还在用收费的文档管理工具?我这有更牛逼的选择!完全免费
Is the programmer's career really short?
Example of vim user automatic command
Why is the pkg/errors tripartite library more recommended for go language error handling?
今天14:00 | 港大、北航、耶鲁、清华、加大等15位ICLR一作讲者精彩继续!
Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers
Submission lottery - light application server essay solicitation activity (may) award announcement
红队第8篇:盲猜包体对上传漏洞的艰难利用过程
Rhcsa Road
Guide for high-end programmers to fish at work
[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
P2592 [ZJOI2008]生日聚会(dp)
Red team Chapter 8: blind guess the difficult utilization process of the package to upload vulnerabilities