[leetcode 141] Linked List Cycle
来源:互联网 发布:iphone6s怎么下载软件 编辑:程序博客网 时间:2024/06/07 12:47
我们可以.用两个指针:one slow and one fast来解决这个问题,slow走一步,fast走两步,slow与fast相遇的地方是slow第一次到达,fast第二次到达的地方
# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def hasCycle(self, head): """ :type head: ListNode :rtype: bool """ slow=fast=head while fast and fast.next: slow=slow.next fast=fast.next.next if id(slow)==id(fast): return True return False
0 0
- LeetCode(141)Linked List Cycle
- LeetCode 141 Linked List Cycle
- LeetCode 141 Linked List Cycle
- LeetCode: Linked List Cycle [141]
- [leetcode 141] Linked List Cycle
- [leetcode]141 Linked List Cycle
- LeetCode 141 Linked List Cycle
- leetcode || 141、Linked List Cycle
- Leetcode[141]-Linked List Cycle
- leetcode-141-Linked List Cycle
- [Leetcode 141] Linked List Cycle
- leetcode 141: Linked List Cycle
- [Leetcode]#141 Linked List Cycle
- leetCode #141 Linked List Cycle
- leetcode: (141) Linked List Cycle
- [leetcode] #141 Linked List Cycle
- 【leetcode】【141】Linked List Cycle
- 【LEETCODE】141-Linked List Cycle
- 强大的datatables
- 11G R2 重做redo日志
- 说明类变量和实例变量的区别
- Happiness
- 中缀表达式转换为后缀表达式c++的实现(数据结构stack)
- [leetcode 141] Linked List Cycle
- TCP状态SYN_RECV , CLOSE_WAIT
- Java Application 和Java Applet程序的主要区别是什么?
- 异常__Could not publish server configuration for Tomcat v8.0 Server at localhost. tomcat启动报错
- 面试问题1
- Openstack : 10、openstack中pbr的作用和解释
- OkHttp使用+文件的上传+断点续传
- Java和C++语言的不同主要包括
- 递归实现逆序输出字符串