博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Leetcode: Linked List Cycle
阅读量:4547 次
发布时间:2019-06-08

本文共 829 字,大约阅读时间需要 2 分钟。

Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?

Analysis: typical Runner Technique. 一次过

1 /** 2  * Definition for singly-linked list. 3  * class ListNode { 4  *     int val; 5  *     ListNode next; 6  *     ListNode(int x) { 7  *         val = x; 8  *         next = null; 9  *     }10  * }11  */12 public class Solution {13     public boolean hasCycle(ListNode head) {14         if (head == null) return false;15         ListNode current = head;16         ListNode runner = head;17         while (runner != null && runner.next != null) {18             runner = runner.next.next;19             current = current.next;20             if (runner == current) return true;21         }22         return false;23     }24 }

 

 

转载于:https://www.cnblogs.com/EdwardLiu/p/3798579.html

你可能感兴趣的文章
高性能、高流量Java Web站点打造的22条建议
查看>>
常见的内存使用不当的情况
查看>>
国外搜索引擎+视频网站
查看>>
又开始写博客了
查看>>
day_7:代理使用
查看>>
mac 下 brew 安装 wine
查看>>
Kubernetes-v1.12.0基于kubeadm部署
查看>>
返回一个整数数组最大子数组的和
查看>>
Java System 类详解 - in, out, err
查看>>
BMP 储存个人理解
查看>>
机器人技术课堂笔记-zjj2016.11.10
查看>>
HTMl5的sessionStorage和localStorage(转)
查看>>
网络是怎样连接的-路由器的包转发操作(上)
查看>>
WPF - EventSetter
查看>>
Superblock mount time is in the future(转载)
查看>>
.Net开源框架列表
查看>>
hadoop 基础, HDFS(块, 元数据)
查看>>
RabbitMQ学习之集群部署
查看>>
Codeforces 1109D. Sasha and Interesting Fact from Graph Theory
查看>>
ASP.NET的URL过滤
查看>>