Medium
💻 Coding
[Machine Learning] Reverse Linked List
Problem Statement
Problem Statement for Reverse Linked List under Machine Learning:
Given the head of a singly linked list, reverse the list, and return its reversed list head node.
Input Constraints:
- 1 <= len(nums) <= 10^5
- Elements fit in memory standard spaces.
Proposed Solution
def reverseList(head):
prev = None
curr = head
while curr:
nxt = curr.next
curr.next = prev
prev = curr
curr = nxt
return prev
Your Progress
Pending Completion
Save Progress?
Login to sync your solutions across all dynamic local and remote sessions.
Join Techlance