335. Circular Linked List — Detect

EasyLinked ListLinked ListCircularFloyd's Cycle Detection

Given the head of a singly linked list, determine if it is a circular linked list (i.e., the last node points back to the first node, forming a complete circle).

A circular list is different from a generic cycle: the tail specifically points back to the head.

Return true if circular (tail.next == head), false otherwise.

Input: Array of node values and boolean is_circular.

Output: Boolean true if circular, false otherwise.

Examples

Example 1
Input: [1,2,3,4,5], is_circular=true
Output: true
Explanation: Last node(5).next = head(1). It's circular.
Example 2
Input: [1,2,3,4,5], is_circular=false
Output: false
Explanation: Last node(5).next = NULL. Not circular.
Example 3
Input: [1], is_circular=true
Output: true
Explanation: Single node pointing to itself.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →