描述
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
分析
经典题,使用两指针,一个每次走一步,另一个走两步,如果两指针相遇,则说明有环。
代码
Python
1 |
|
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
经典题,使用两指针,一个每次走一步,另一个走两步,如果两指针相遇,则说明有环。
1 |
|
近期评论