Time: 35 ms (67.17%), Space: 13.9 MB (60.50%) - LeetHub

This commit is contained in:
Deven
2023-01-19 22:07:32 -05:00
parent ca47931756
commit a574b3d20e
@@ -0,0 +1,19 @@
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def swapPairs(self, head: Optional[ListNode]) -> Optional[ListNode]:
if head == None or head.next == None:
return head
first = head
second = head.next
first.next = second.next
second.next = first
first.next = self.swapPairs(first.next)
return second