标签:link tno nbsp bool out can next eterm ace
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
题目含义:判断一个列表是否有环路
1 public boolean hasCycle(ListNode head) { 2 if (head == null) return false; 3 ListNode walker = head; 4 ListNode runner = head; 5 while (runner.next !=null && runner.next.next != null) 6 { 7 walker = walker.next; 8 runner = runner.next.next; 9 if (walker == runner) return true; 10 } 11 return false; 12 }
标签:link tno nbsp bool out can next eterm ace
原文地址:http://www.cnblogs.com/wzj4858/p/7724234.html