ListNode *swapPairs(ListNode *head) {
        if (head == nullptr || head->next == nullptr)
            return head;
        ListNode *it = head;
        head = head->next;
        it->next = head->next;
        head->next = it;
        while (it->next != nullptr && it->next->next != nullptr) {
            ListNode *temp = it->next;
            it->next = it->next->next;
            temp->next = it->next->next;
            it->next->next = temp;
            it = it->next->next;
        }
        return head;
    }

相关文章:

  • 2021-10-03
  • 2022-01-13
  • 2021-06-29
  • 2021-08-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-11
  • 2021-07-30
  • 2021-06-27
  • 2022-12-23
  • 2021-07-19
相关资源
相似解决方案