kucheasysa

Algoverse_adesh_43

Jul 12th, 2024
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. #User function Template for python3
  2.  
  3. '''
  4. class Node:
  5.    def __init__(self, data):
  6.        self.data = data  
  7.        self.next = None
  8.        self.prev = None
  9. '''
  10.  
  11.  
  12. class Solution:
  13.     def reverseDLL(self, head):
  14.         if head.next == None:
  15.             return head
  16.        
  17.         else:
  18.             curr = head
  19.             prevv = None
  20.             while curr != None:
  21.                 prevv = curr
  22.                 curr.next, curr.prev =  curr.prev , curr.next
  23.                 curr = curr.prev
  24.            
  25.             return prevv
  26.  
  27.  
  28.  
  29.  
Advertisement
Add Comment
Please, Sign In to add comment