Given a linked list, determine if it has a cycle in it. Example Given -21->10->4->5, tail connects to node index 1, return true
Challenge Follow up: Can you solve it without using extra space?
Solution:
This is an easy problem. Just use two pointers to point to head. One pointer go twice speed of the second pointer. If they meet before the fast touch the end of the list, return true; Else return false;
近期评论