Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
代码:
解题思路:定义快慢指针,快指针要是指向了null,那么没有环;快慢指针相遇,那么就存在环。
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
解题思路:定义快慢指针,快指针要是指向了null,那么没有环;快慢指针相遇,那么就存在环。