A C# 3-Line Solution


  • 0
    L
    public bool HasCycle(ListNode head) {
        for(ListNode help = head == null ? null : head.next; help != null && help.next != null; help = help.next.next, head = head.next)
            if(help == head) return true;
        return false;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.