linked-list-cycle
来源:互联网 发布:淘宝网雪纺女装 编辑:程序博客网 时间:2024/05/19 13:55
1、链接:linked-list-cycle 来源:牛客网
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
2、思路:设置快慢指针,如果有cycle则会相遇,没有的话,快指针最终会走到tail
3、代码:
public class Solution { boolean isCycle = false; public boolean hasCycle(ListNode head) { ListNode first = head; ListNode second = head; while(second != null){ first = first.next; if(second.next == null) break; second = second.next; second = second.next; if(first == second){ isCycle = true; break; } } return isCycle; }}
阅读全文
0 0
- leetcode Linked List Cycle & Linked List Cycle ||
- Linked List Cycle II Linked List Cycle
- 【LeetCode】Linked List Cycle
- Leetcode: Linked List Cycle
- Leetcode Linked List Cycle
- Linked List Cycle
- Linked List Cycle II
- Linked List Cycle
- Linked List Cycle
- Linked List Cycle II
- Leetcode: Linked List Cycle
- LeetCode:Linked List Cycle
- Linked List Cycle II
- Linked List Cycle
- Linked List Cycle II
- [LeetCode]Linked List Cycle
- Linked List Cycle
- LeetCode | Linked List Cycle
- 面试小记2
- 初识网络爬虫之二:httplib与urllib实现
- Python初级教程
- Linux教程【8】-文件搜索命令
- 四、关于osmdroid地图源的疑问
- linked-list-cycle
- 银行业务对列简单模拟
- 3、jQuery的属性与样式--样式篇
- 初始网络爬虫之三:网络爬虫最常用的requests库
- php微信开发解决{"errcode":40016,"errmsg":"invalid button size hint: [pqd5ea0809vr22]"}
- Strust2人事管理系统
- PyQt5学习笔记02----初探Qt Designer 设计师
- Android自定义日历
- 千年古银杏树成‘网红’