leetcode_141. Linked List Cycle 判断链表中是否有环
来源:互联网 发布:轻松网络销售招聘 编辑:程序博客网 时间:2024/06/05 10:22
题目:
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
题意:
给定一个链表,判断它是否含有环(要求不能使用额外的空间)
代码:
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def hasCycle(self, head):
"""
:type head: ListNode
:rtype: bool
"""
if head == None :
return False
else :
while head != None :
if head.val == 100000000 :
return True
else :
head.val = 100000000
head = head.next
return False
笔记:
基本思想是,用head指针走过的节点,将节点值修改为一个很大的值,然后遍历链表,当遇到节点值为设置的很大的值时,说明这个节点之前被遍历过,即链表里链表有环
- leetcode_141. Linked List Cycle 判断链表中是否有环
- 判断链表是否有环 Linked List Cycle, Linked List Cycle II
- 判断链表是否有环 Linked List Cycle
- Linked List Cycle --判断链表是否有环
- leetcode--Linked List Cycle--判断链表是否有环
- Linked List Cycle 判断链表是否有环
- 141. Linked List Cycle 判断单链表中是否有环
- 141. Linked List Cycle (判断单链表中是否有环)
- 141. Linked List Cycle | 判断单链表是否有环
- Linked List Cycle:判断链表是否有环
- leetcode_141.Linked List Cycle ?待解决
- Linked List Cycle-- 判断一个单向链表中是否有环存在
- Linked List Cycle 判断链表是否有环,如果有环,找到环的入口
- LeetCode | Linked List Cycle(判断链表是否有环)
- LeetCode OJ 之 Linked List Cycle (判断链表是否有环)
- LeetCode OJ 之 Linked List Cycle II(判断链表是否有环 - 二)
- 141.Linked List Cycle (判断一个单链表是否有环)
- 【leetcode】Linked List Cycle II,判断链表是否有环
- 笔记-CCNA与网络安全 第8章 网络安全
- 浅析spring mvc和struts2的区别及个人总结
- phpstudy升级mysql数据库
- 使用base64 对Json 的返回数据进行优化
- XML查询操作
- leetcode_141. Linked List Cycle 判断链表中是否有环
- 静态的京东商城网站编写01(学完css和html之后就可以编写)
- CSS—实现页面的水平垂直居中,只是页面
- 静态cell和动态cell混用
- HDU 1125 (DP)
- C#语言与面向对象技术(4)
- D3D11教程二十八之PlannarReflection(基于stencilBuffer的实现)
- rpm 用法
- file类