Advertisement
Iam_Sandeep

reverse a linked list

Sep 7th, 2021
1,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. class Solution:
  2.     def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
  3.         if head==None or head.next==None:
  4.             return head
  5.         def change(first,second):
  6.             if second.next==None:
  7.                 second.next=first
  8.                 return second
  9.             else:
  10.                 t=change(second,second.next)
  11.                 second.next=first
  12.                 return t
  13.         head=change(None,head)
  14.         return head
  15.            
  16.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement