Linked List Cycle

by atalaykutlay

Solution to the "Linked List Cycle" question on Leetcode.

Linked List Cycle
1class Solution:
2    def hasCycle(self, head: Optional[ListNode]) -> bool:
3        if head is None:
4            return False
5        
6        while head.next:
7            if head.val is None:
8                return True
9
10            head.val = None
11            head = head.next
12        
13        return False

Share

Share
Video
A cool 10 sec video.
Share
Detailed
Title, description, and syntax highlighted code.
Share
Simple
Syntax highlighted code with gradient background colored presentation.

Comments

It looks like there is no comment for this snippet. Leave the first one!
You need to login to send a comment.

Similar Snippets

Count Number of Texts
Count Number of Texts

Solution to "Count Number of Texts" question on Leetcode.

Language: python12 months ago
Quicksort in Python
Quicksort in Python

An easy quicksort implementation in Python.

Language: python13 months ago
Second Minimum Node In a Binary Tree
Second Minimum Node In a Binary Tree

Solution to "Second Minimum Node In a Binary Tree" on Leetcode.

Language: python11 months ago