/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Solution { public boolean hasCycle(ListNode head) { if(head == null){ return false; } ListNode slow = head; ListNode fast = head.next; while (fast != null){ if(slow == fast){ return true; } slow = slow.next; fast = fast.next; if(fast != null){ fast = fast.next; } } return false; } }
相关推荐
javascript js_leetcode题解之142-linked-list-cycle-ii.js
javascript js_leetcode题解之141-linked-list-cycle.js
python python_leetcode题解之142_Linked_List_Cycle_II
python python_leetcode题解之141_Linked_List_Cycle
Linked List Cycle**:判断链表是否有环,如有,找到环的入口节点。 - **19. Remove Nth From End**:移除链表中的第 n 个节点。 - **206. Reverse Linked List**:反转整个链表。 - **21. Merge Two Sorted ...
若两者能够相遇,则有环,否则,若在这个过程中检测到了链表尾,则无环。 Reverse Linked List Reverse a linked list. Challenge: Reverse it in-place and in one-pass A linked list can be reversed either ...
linked-list-cycle-ii 链表 linked-list-cycle 链表 copy-list-with-random-pointer 复杂度 single-number 动态规划 candy 贪心 gas-station 动态规划 palindrome-partitioning-ii 动态规划 triangle 树 sum-root-to...
答案leetcode-java leetcode.com 的 Java 答案 ================索引================ com.leetcode.array Search a 2D Matrix Spiral Matrix com.leetcode.list Linked List Cycle Linked List Cycle II Remove ...
preorder-traversal链表reorder-list链表linked-list-cycle-ii链表linked-list-cycle动态规划word-break-ii动态规划word-break链表copy-list-with-random-pointer复杂度single-number-ii复杂度single-number动态规划
141-环形链表:linked-list-cycle 142-环形链表:linked-list-cycle-ii 160-相交链表:intersection-of-two-linked-lists 206-反转一个单链表:reverse-linked-list 20-有效的括号:valid-parentheses 150-逆波兰表达式求...
leetcode中325题python leetcode 以 参考 和 Hash相关 1_两数之和 ...linked-list-cycle-ii 143 重排链表 reorder-list 148 排序链表 sort-list 234 回文链表 palindrome-linked-list 双指针遍历/滑动
leetcode怎么销号 LeetCode便签 Linked List Cycle 问题描述 Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 解决思路 声明一个慢指针和一个快...
* [Linked List](https://github.com/kamyu104/LeetCode#linked-list) * [Stack](https://github.com/kamyu104/LeetCode#stack) * [Queue](https://github.com/kamyu104/LeetCode#queue) * [Heap]...
leetcode ...List(链表) ID Difficulty Title Python C++ Blog 21 Easy Merge Two Sorted Lists 83 * Remove Duplicates from Sorted List 141 * Linked List Cycle 160 * Intersection of Two Linke
leetcode有效期 Datawhale-Coding All Tasks Task 1:数组和链表(2天) 时间:2019-08-03 21:00 - 2019-08-05 21:00 讨论&CR时间: 2019-08-05 21:00 - 2019-08-05 22:30 【数组】 实现一个支持动态扩容的数组 实现...
leetcode中文版 LeetCode/Cpp 本人刷题记录在此,包含题意理解与算法思路,包含在Cpp文件内部注释,后续会持续更新。 有不懂的可以联系ji648513181,同时也欢迎志同道合O的朋友一起合作更新。 已更新剑指Offer答案...
List(链表) ID Difficulty Title Java Python 21 Easy Merge Two Sorted Lists 83 Easy Remove Duplicates from Sorted List 141 Easy Linked List Cycle 160 Easy Intersection of Two Linked Lists 203 Easy ...
linked-list-cycle/Solution.993783.java $ tree . ├── add-binary │ └── Solution.665166.java ├── add-two-numbers │ └── Solution.666385.java ├── balanced-binary-tree │ └── ...
- **Linked List Cycle**:检测链表中的环。 - **Remove Duplicates from Sorted List**:从已排序的链表中移除重复项。 - **Merge Sorted Lists**:合并两个已排序的链表。 - **Reverse Linked List**:反转...
leetcode-java leetcode刷题笔记 已做题目列表 1.Two Sum 3.Longest Substring Without Repeating Characters 5.Longest Palindromic Substring 20.Valid Parentheses 26.Remove Duplicates from Sorted Array 53....