Skip to content

Latest commit

 

History

History

03-01 Singly Linked List Cycle Check

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Singly Linked List Cycle Check

Problem

Given a singly linked list, write a function which takes in the first node in a singly linked list and returns a boolean indicating if the linked list contains a "cycle".

A cycle is when a node's next point actually points back to a previous node in the list. This is also sometimes known as a circularly linked list.

You've been given the Linked List Node class code:

class Node(object):

    def __init__(self,value):

        self.value = value
        self.nextnode = None

Leetcode: https://leetcode.com/problems/linked-list-cycle/

Code

Write your code in the form:

def cycle_check(node):
    pass #Your function should return a boolean