Given head, the head of a singly linked list, find if the linked list is circular or not. A linked list is called circular if it not NULL terminated and all nodes are connected in the form of a cycle. An empty linked list is considered as circular.
Note: The linked list does not contains any inner loop.
Example 1:
Input:
LinkedList: 1->2->3->4->5
(the first and last node is connected,
i.e. 5 --> 1)
Output: 1
Example 2:
Input:
LinkedList: 2->4->6->7->5->1
Output: 0
Your Task:
The task is to complete the function isCircular() which checks if the given linked list is circular or not. It should return true or false accordingly. (the driver code prints 1 if the returned values is true, otherwise 0)
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
1 <=Number of nodes<= 100

Difficulty: EASY
Tags: Data structures
Skill types: Data structures
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).

Starter code:
#class Node:

#    def __init__(self, data):

#        self.data = data

#        self.next = None





# your task is to complete this function

# function should return true/false or 1/0

def isCircular(head):

    # Code here



Solutions:
def isCircular(head):
	if head.next == head:
		return 1
	elif head.next == None:
		return 0
	temp = head.next
	while temp.next != None and temp.next != head:
		temp = temp.next
	if temp.next == None:
		return 0
	else:
		return 1


def isCircular(head):
	temp = head
	while temp:
		if temp.next is head:
			return True
		temp = temp.next
	return False


def isCircular(head):
	if head.next == None:
		return False
	if head.next == head:
		return True
	curr = head
	while True:
		if curr.next == None:
			return False
		elif curr.next == head:
			return True
		else:
			curr = curr.next


def isCircular(head):
	if head == None:
		return True
	curr = head.next
	while curr is not None and curr is not head:
		curr = curr.next
	return curr == head


def isCircular(head):
	p = head
	n = 1
	if head == None:
		return False
	else:
		while (p.next != head and n != 100) and p.next != None:
			n += 1
			p = p.next
	if p.next == head:
		return True
	else:
		return False


def isCircular(head):
	slow = head
	fast = head
	if head is None:
		return False
	while fast and fast.next:
		fast = fast.next.next
		slow = slow.next
		if fast == slow:
			return True
	return False


def isCircular(head):
	N = 102
	temp = head
	itr = 0
	while temp != None and itr < N:
		temp = temp.next
		itr = itr + 1
	if itr <= 100:
		return 0
	else:
		return 1


def isCircular(head):
	front = head
	while front is not None:
		front = front.next
		if front == head:
			return True
	return False


def isCircular(head):
	p = head
	while p.next != head:
		if not p.next:
			return 0
		p = p.next
	return 1


def isCircular(head):
	temp = head
	while temp.next != head:
		if not temp.next:
			return 0
		temp = temp.next
	return 1


def isCircular(head):
	temp = head
	flag = 0
	while temp:
		if temp.next == head:
			return 1
		temp = temp.next
	return 0


def isCircular(head):
	p1 = head
	while p1.next != head:
		if not p1.next:
			return 0
		p1 = p1.next
	return 1


def isCircular(head):
	(dummy1, dummy2) = (head, head)
	if dummy1 == None:
		return 1
	while dummy1:
		dummy1 = dummy1.next
		if dummy1 == dummy2:
			return 1
	return 0


def isCircular(head):
	m = head
	while m.next != head:
		if not m.next:
			return 0
		m = m.next
	return 1


def isCircular(head):
	curr = head
	while curr.next is not head:
		if not curr.next:
			return 0
		curr = curr.next
	return 1


def isCircular(head):
	if head is None:
		return
	curr = head.next
	while curr != head:
		if curr == None:
			return 0
		curr = curr.next
	return 1


def isCircular(head):
	temp = head.next
	while temp != head and temp != None:
		temp = temp.next
	return temp == head


def isCircular(head):
	temp = head
	count = 101
	while count != 0:
		if temp.next is not None:
			temp = temp.next
			if temp == head:
				return True
				break
		else:
			break
		count -= 1
	return False


def isCircular(head):
	if head is None:
		return
	curr = head
	while curr.next != None:
		curr = curr.next
		if curr == head:
			return head
	return


def isCircular(head):
	cur = head
	if head is None:
		return 1
	elif head.next == head:
		return 1
	else:
		cur = head
		while cur.next is not None:
			cur = cur.next
			if cur == head:
				return 1
		return 0


def isCircular(head):
	temp = head
	if not temp:
		return True
	else:
		fs = head
		while fs:
			if fs:
				fs = fs.next
				if fs:
					fs = fs.next
					temp = temp.next
			if not fs:
				return False
			if fs == temp:
				return True


def isCircular(head):
	if head == None:
		return True
	if head.next == None:
		return False
	temp = head.next
	while temp != None and temp != head:
		temp = temp.next
	if temp == head:
		return True
	if temp == None:
		return False


def isCircular(head):
	next_node = head
	head_node = head
	while next_node.next:
		if next_node.next == head:
			return True
		else:
			next_node = next_node.next
	return False


def isCircular(head):
	l = head
	if not head.next:
		return False
	r = head.next.next
	while l != r:
		try:
			r = r.next.next
		except:
			return False
		l = l.next
	return True


def isCircular(head):
	curr = head.next
	while curr != None and curr != head:
		curr = curr.next
	return curr == head


def isCircular(head):
	current = head
	temp = head
	while temp:
		if temp.next == current:
			return True
		else:
			temp = temp.next
	return False


def isCircular(head):
	if head == None:
		return 1
	fast = slow = head
	while fast and fast.next:
		slow = slow.next
		fast = fast.next.next
		if fast == slow:
			return 1
	return 0


def isCircular(head):
	if head == None:
		return True
	else:
		cur = head.next
		while cur != None:
			if cur.next == head:
				return True
			cur = cur.next
		return False


def isCircular(head):
	curr = head
	while curr:
		curr = curr.next
		if curr == head:
			return 1
	return 0


def isCircular(head):
	n = head
	while n is not None:
		if n.next == head:
			return 1
		n = n.next
	return 0


def isCircular(head):
	last = head
	while last:
		if last.next == head:
			return True
		else:
			last = last.next


def isCircular(head):
	l1 = head
	while l1:
		if l1.next == head:
			return 1
		else:
			l1 = l1.next
	return 0


def isCircular(head):
	if not head:
		return True
	curr = head
	curr = curr.next
	while curr:
		if curr == head:
			return True
		elif not curr:
			return False
		curr = curr.next
	return False


def isCircular(head):
	f = head
	next1 = f.next
	while next1 is not None:
		if next1.next is f:
			return True
		next1 = next1.next
	return False


def isCircular(head):
	tmp = head
	current = head.next
	while current != None:
		if tmp == current:
			return 1
		current = current.next
	return 0


def isCircular(head):
	if head == None:
		return 0
	curr = head
	while True:
		if curr.next == head:
			return True
		if curr.next == None:
			return False
		curr = curr.next


def isCircular(head):
	if head == None:
		return True
	else:
		temp = head.next
		while temp != None:
			if temp.next == head:
				return True
			temp = temp.next
		return False


def isCircular(head):
	if not head:
		return True
	map = {}
	temp = head
	while temp:
		if map.get(temp):
			return True
		map[temp] = temp
		temp = temp.next
	return False


def isCircular(head):
	p = head
	while p != None:
		p = p.next
		if p == head:
			return 1
	return 0


def isCircular(head):
	if head is None:
		return True
	slow_ptr = head
	fast_ptr = head.next
	while fast_ptr is not None and fast_ptr.next is not None:
		slow_ptr = slow_ptr.next
		fast_ptr = fast_ptr.next.next
		if slow_ptr == fast_ptr:
			return True
	return False


def isCircular(head):
	cur1 = head
	cur2 = head
	while cur2 != None and cur2.next != None:
		cur1 = cur1.next
		cur2 = cur2.next.next
		if cur1 == cur2:
			return True
	return False


def isCircular(head):
	tmp = head
	while head.next:
		if tmp == head.next:
			return 1
		head = head.next
	return 0


def isCircular(head):
	curr = head
	while curr.next != head and curr.next != None:
		curr = curr.next
	if curr.next == head:
		return 1
	if curr.next == None:
		return 0


def isCircular(head):
	if head is None:
		return True
	else:
		c = head.next
		while c != None:
			if c.next == head:
				return True
			c = c.next
		return False


def isCircular(head):
	temp = head
	while temp != None:
		temp = temp.next
		if temp == head:
			return 1
	return 0


def isCircular(head):
	pointer = head
	while pointer and pointer.next != head:
		pointer = pointer.next
	if not pointer:
		return False
	if pointer.next == head:
		return True


def isCircular(head):
	if head == None:
		return True
	if head.next == head:
		return True
	node = head.next
	while node != head:
		if node == None:
			return False
		node = node.next
	return True


def isCircular(head):
	first = head
	try:
		current = head.next
		while current.next != None:
			if first == current:
				return 1
			current = current.next
	except:
		return 0
	return 0