Leetcode #141 Linked List Cycle Python
来源:互联网 发布:松下fpwin编程手册 编辑:程序博客网 时间:2024/06/01 08:05
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
Difficulty:Medium
不占用额外地址的做法,两个node一个每次跳一次,一个每次跳两下next,如果碰到none就返回False,如果这个两个node重合了就说明有一个circle。
# 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 """ p = head pNext=head while (p is not None) and (pNext is not None): if p.next is None or pNext.next is None: return False p = p.next pNext = pNext.next.next if p==pNext: return True return False
0 0
- Leetcode #141 Linked List Cycle Python
- Leetcode@python Linked List Cycle
- 【leetcode】Linked List Cycle (python)
- 【leetcode】Linked List Cycle (python)
- 【LeetCode】【Python】Linked List Cycle
- Leetcode-Linked List Cycle-Python
- [Leetcode][python]Linked List Cycle/Linked List Cycle II
- 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
- 不要把 Python 写成 C 语言版的 Python
- USACO 1.1 Broken Necklace
- 基于阿里云Ubuntu14.04 64bit部署WordPress博客系统
- How To Create A Struts 2 Web Application
- 新建Android工程报错:'Building workspace' has encountered a problem...解决办法
- Leetcode #141 Linked List Cycle Python
- iOS部分-UI基础控件 - 01天 入门 第11课 上下左右移动
- 635 Oh, my goddess【优先队列+bfs】
- iOS部分-UI基础控件 - 01天 入门 第12课 代码优化
- PHP中的运算符
- imkdzvutpsotrzub
- 【笔记】css绘制带三角的气泡
- Unity优化大全(八)之 GPU-Ligh和其他
- Shader基本语法