public boolean hasCycle(ListNode head) {

		if (head == null || head.next == null)
			return false;

		ListNode slow = head;
		ListNode fast = head;

		while (true) {
			slow = slow.next;
			if (fast.next == null)
				return false;
			else
				fast = fast.next.next;

			if (slow.equals(fast))
				return true;

			if ((slow == null) || (fast == null))
				return false;
		}
	}