当前位置:网站首页>LeetCode 234. Palindrome linked list
LeetCode 234. Palindrome linked list
2022-07-05 03:00:00 【Abby's daily life】
https://leetcode-cn.com/problems/palindrome-linked-list/
Ideas
- Linked list element value storage list
- Double pointer (0 Start , Start at the end ) Determine if the values are equal
/** Linked list values are added to the set Double pointer */
public boolean isPalindrome(ListNode head) {
List<Integer> list = new ArrayList<>();
ListNode curr = head;
while (curr != null) {
list.add(curr.val);
curr = curr.next;
}
int first = 0;
int last = list.size() - 1;
while (first < last) {
if (list.get(first) != list.get(last)) {
return false;
}
first++;
last--;
}
return true;
}
边栏推荐
- tuple and point
- Watch the online press conference of tdengine community heroes and listen to TD hero talk about the legend of developers
- Master Fur
- 有个疑问 flink sql cdc 的话可以设置并行度么, 并行度大于1会有顺序问题吧?
- Openresty ngx Lua Execution stage
- Port, domain name, protocol.
- ELK日志分析系统
- Elfk deployment
- qrcode:将文本生成二维码
- Pytest (4) - test case execution sequence
猜你喜欢
ASP. Net core 6 framework unveiling example demonstration [01]: initial programming experience
Flume配置4——自定义MYSQLSource
IPv6 experiment
Marubeni Baidu applet detailed configuration tutorial, approved.
Sqoop安装
Zabbix
2021 Li Hongyi machine learning (1): basic concepts
Devtools的簡單使用
Avoid material "minefields"! Play with super high conversion rate
腾讯云,实现图片上传
随机推荐
SQL injection exercise -- sqli Labs
Usage scenarios and solutions of ledger sharing
There is a question about whether the parallelism can be set for Flink SQL CDC. If the parallelism is greater than 1, will there be a sequence problem?
Acwing第 58 场周赛【完结】
问题解决:AttributeError: ‘NoneType‘ object has no attribute ‘append‘
Flume configuration 4 - customize mysqlsource
LeetCode146. LRU cache
Elk log analysis system
Talk about the SQL server version of DTM sub transaction barrier function
Why are there fewer and fewer good products produced by big Internet companies such as Tencent and Alibaba?
Hot knowledge of multithreading (I): introduction to ThreadLocal and underlying principles
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
【微服务|SCG】Filters的33种用法
数据库和充值都没有了
openresty ngx_ Lua execution phase
qrcode:将文本生成二维码
Tencent cloud, realize image upload
[daily problem insight] Li Kou - the 280th weekly match (I really didn't know it could be so simple to solve other people's problems)
From task Run get return value - getting return value from task Run
【LeetCode】106. Construct binary tree from middle order and post order traversal sequence (wrong question 2)