leetcode经典例题第九题,求证一个链表是否有环。
题目描述
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
解题思路
环的长度就是快指针比慢指针多走的长度,因此快慢指针如果能相遇,那么表明有环,否则就表示没有环。
代码提交
1 |
public class { |
leetcode经典例题第九题,求证一个链表是否有环。
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
环的长度就是快指针比慢指针多走的长度,因此快慢指针如果能相遇,那么表明有环,否则就表示没有环。
1 |
public class { |
近期评论