当前位置:网站首页>判断链表是否是回文链表
判断链表是否是回文链表
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;
边栏推荐
- 【SQL语句】请问这边为什么select出了两个上海,查询出了不同的count我想让他变成一个上海,count只显示一个总和
- The Department came to a Post-00 test paper king who took out 25K. The veteran said it was really dry, but it had been
- Défaillance lors du démarrage de la machine virtuelle VMware: le poste de travail VMware n'est pas compatible avec hyper - V...
- 【Kotlin】高阶函数介绍
- sql刷题627. 变更性别
- Hi Fun Summer, play SQL planner with starrocks!
- 红队第10篇:coldfusion反序列化过waf改exp拿靶标的艰难过程
- Buuctf gold III
- How to use F1 to F12 correctly on laptop keyboard
- VMware virtual machine failed during startup: VMware Workstation is incompatible with hyper-v
猜你喜欢
VMware virtual machine failed during startup: VMware Workstation is incompatible with hyper-v
免费抽奖 | 《阿巴豆》探索未来系列盲盒数字版权作品全网首发!
阿里云、追一科技抢滩对话式AI
模板引擎Velocity 基础
[nodemon] app crashed - waiting for file changes before starting... resolvent
Sweden announced its decision to exclude Huawei 5g equipment, but Huawei has successfully found a new way out
今天14:00 | 港大、北航、耶鲁、清华、加大等15位ICLR一作讲者精彩继续!
独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
Learn selenium to simulate mouse operation, and you can be lazy a little bit
Template engine velocity Foundation
随机推荐
模板引擎Velocity 基礎
全面看待企业数字化转型的价值
Rhcsa Road
巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...
sql刷题1050. 合作过至少三次的演员和导演
How to use F1 to F12 correctly on laptop keyboard
Chinese diosgenin market forecast and investment strategy report (2022 Edition)
Zabbix2.2监控之系统及应用日志监控报警
Endeavouros mobile hard disk installation
博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
Comprehensively view the value of enterprise digital transformation
Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022
P2592 [ZJOI2008]生日聚会(dp)
IM即時通訊開發實現心跳保活遇到的問題
【Hot100】20. Valid parentheses
软件工程导论——第六章——详细设计
Buuctf gold III
Rhcsa Road
【Kotlin】高阶函数介绍
【flask入门系列】Cookie与Session