Professional Documents
Culture Documents
Ankit Raj - 21BCS8715 - Day4 - It Skills
Ankit Raj - 21BCS8715 - Day4 - It Skills
UID : 21BCS8715
SECTION/ GROUP : 21BCS-CC-652-B
SUBJECT : IT SKILLS
DAY-4
CODE:
1. Partition List
class Solution:
def hasCycle(self, head: ListNode) -> bool:
# Initialize slow and fast pointers
slow = head
fast = head
# No cycle found
return False
# Find the correct position to insert current node in the sorted list
prev = dummy
while prev.next and prev.next.val < current.val:
prev = prev.next
return dummy.next
return dummy.next
return True
# No cycle found
return False
Outputs: