本文主要是介绍Java | Leetcode Java题解之第141题环形链表,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
题解:
public class Solution {public boolean hasCycle(ListNode head) {if (head == null || head.next == null) {return false;}ListNode slow = head;ListNode fast = head.next;while (slow != fast) {if (fast == null || fast.next == null) {return false;}slow = slow.next;fast = fast.next.next;}return true;}
}
这篇关于Java | Leetcode Java题解之第141题环形链表的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!