Skip to content

Commit

Permalink
Day 12: Attempt 2: 141_Linked_List_Cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsnh1522 committed Feb 27, 2024
1 parent 743fc2a commit eadd4a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Remember, the 75 Hard Challenge is about personal growth and discipline. Stay co
- Day 11: [155. Min Stack](https://leetcode.com/problems/min-stack/)
- Day 11: [150. Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/)
<!-- - Day 11: [224. Basic Calculator](https://leetcode.com/problems/basic-calculator/) -->
- Day 12: [141. Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/)



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import Optional
# Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
self.next = None

class Solution:
def hasCycle(self, head: Optional[ListNode]) -> bool:
tortoise = head
hare = head
while hare and hare.next:
tortoise = tortoise.next
hare = hare.next.next
if tortoise == hare:
return True
return False

0 comments on commit eadd4a2

Please sign in to comment.