kucheasysa

Algoverse_adesh_34

Jul 3rd, 2024
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. # Definition for singly-linked list.
  2. # class ListNode:
  3. #     def __init__(self, val=0, next=None):
  4. #         self.val = val
  5. #         self.next = next
  6. class Solution:
  7.     def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
  8.         l1= None
  9.         current = head
  10.  
  11.         while current:
  12.             nex = current.next
  13.             current.next = l1
  14.             l1=current
  15.             current = nex
  16.         return l1
Advertisement
Add Comment
Please, Sign In to add comment