当前位置:网站首页>判断链表是否是回文链表
判断链表是否是回文链表
2022-07-01 16:26:00 【鸭蛋炒西红柿】
第一步先将链表的值放在数组列表里,然后通过双指针来判断是否是回文链表,一个指针从头开始,另一个指针从尾开始,依次遍历,如果遇到的值不一样直接返回false,值一样则继续遍历,直到两个索引相遇。
第一步:
List<Integer> arr=new ArrayList<Integer>();
ListNode currentNode=head;
Boolean flag=true;
while (currentNode!=null){
arr.add(currentNode.val);
currentNode=currentNode.next;
}第二步:
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;边栏推荐
- P2893 [usaco08feb] making the grade g (DP & priority queue)
- UML tourism management system "suggestions collection"
- How to restore the system of Sony laptop
- 【Hot100】19. Delete the penultimate node of the linked list
- Five years after graduation, I became a test development engineer with an annual salary of 30w+
- [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
- Flux d'entrées / sorties et opérations de fichiers en langage C
- How to use MySQL language for row and column devices?
- Rhcsa Road
- 挖财学堂班主任给的证券账户安全吗?能开户吗?
猜你喜欢

MLPerf Training v2.0 榜单发布,在同等GPU配置下百度飞桨性能世界第一

Défaillance lors du démarrage de la machine virtuelle VMware: le poste de travail VMware n'est pas compatible avec hyper - V...

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

Apple's self-developed baseband chip failed again, which shows Huawei Hisilicon's technological leadership

Talking from mlperf: how to lead the next wave of AI accelerator

为国产数据库添砖加瓦,StoneDB 一体化实时 HTAP 数据库正式开源!

How to use MySQL language for row and column devices?
![[nodemon] app crashed - waiting for file changes before starting... resolvent](/img/ee/9830afd86e092851a2a906cb994949.png)
[nodemon] app crashed - waiting for file changes before starting... resolvent

SQLServer查询: a.id与b.id相同时,a.id对应的a.p在b.id对应的b.p里找不到的话,就显示出这个a.id和a.p

嗨 FUN 一夏,与 StarRocks 一起玩转 SQL Planner!
随机推荐
Activity的生命周期和启动模式详解
博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
UML旅游管理系统「建议收藏」
Submission lottery - light application server essay solicitation activity (may) award announcement
Installation and use of sqoop
用手机在同花顺上开户靠谱吗?这样有没有什么安全隐患
Problems encountered in IM instant messaging development to maintain heartbeat
今天14:00 | 港大、北航、耶鲁、清华、加大等15位ICLR一作讲者精彩继续!
VMware 虚拟机启动时出现故障:VMware Workstation 与 Hyper-v 不兼容...
Bugku's file contains
【Hot100】19. Delete the penultimate node of the linked list
数据库系统原理与应用教程(006)—— 编译安装 MySQL5.7(Linux 环境)
芯片供应转向过剩,中国芯片日产增加至10亿,国外芯片将更难受
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
Comprehensively view the value of enterprise digital transformation
【Hot100】17. Letter combination of telephone number
UML tourism management system "suggestions collection"
Motion capture system for apple picking robot
Leetcode 216 combined summation III -- backtracking method
P2893 [usaco08feb] making the grade g (DP & priority queue)