您的位置:首页 > 其它

141.Linked List Cycle (判断一个单链表是否有环)

2015-07-30 15:06 260 查看
public class Solution {

    public boolean hasCycle(ListNode head) {

     ListNode slow = head, fast = head;

    

      while (fast != null && fast.next != null) {

        slow = slow.next;

        fast = fast.next.next;

    

        if (slow == fast) 

            return true;

      }

    

      return false;

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: