首页 > 编程语言 > 详细

LeetCode-141 Linked List Cycle Solution (with Java)

时间:2020-03-02 13:52:48      阅读:41      评论:0      收藏:0      [点我收藏+]

1. Description: 技术分享图片

Notes:

技术分享图片

2. Examples: 技术分享图片

技术分享图片

3.Solutions:

 1 /**
 2  * Created by sheepcore on 2019-05-14
 3  * Definition for singly-linked list.
 4  * class ListNode {
 5  *     int val;
 6  *     ListNode next;
 7  *     ListNode(int x) {
 8  *         val = x;
 9  *         next = null;
10  *     }
11  * }
12  */
13 public boolean hasCycle(ListNode head) {
14     ListNode p = head,pre = head;
15     while(p != null && p.next != null){
16         if (p.next == head) return true;
17         p = p.next;
18         pre.next = head;
19         pre = p;
20     }
21     return false;
22 }

 

LeetCode-141 Linked List Cycle Solution (with Java)

原文:https://www.cnblogs.com/sheepcore/p/12395121.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!