diff --git a/linked_lists/swap_every_two_nodes.py b/linked_lists/swap_every_two_nodes.py index 999bbac..3e1de31 100644 --- a/linked_lists/swap_every_two_nodes.py +++ b/linked_lists/swap_every_two_nodes.py @@ -3,21 +3,20 @@ # author: bt3gl -class ListNode: +class Node: def __init__(self, val=0, next=None): self.val = val self.next = next -def swap_pairs(head: Optional[ListNode]) -> Optional[ListNode]: +def swap_pairs(head: Optional[Node]) -> Optional[Node]: + if not head or not head.next: return head - ## nodes to be swapped first_node = head second_node = head.next - # swapping first_node.next = swap_pairs(second_node.next) second_node.next = first_node