当前位置:   article > 正文

C语言 | Leetcode C语言题解之第24题两两交换链表中的节点_两两交换链表中的节点c语言

两两交换链表中的节点c语言

题目:

题解:

  1. struct ListNode* swapPairs(struct ListNode* head) {
  2. struct ListNode dummyHead;
  3. dummyHead.next = head;
  4. struct ListNode* temp = &dummyHead;
  5. while (temp->next != NULL && temp->next->next != NULL) {
  6. struct ListNode* node1 = temp->next;
  7. struct ListNode* node2 = temp->next->next;
  8. temp->next = node2;
  9. node1->next = node2->next;
  10. node2->next = node1;
  11. temp = node1;
  12. }
  13. return dummyHead.next;
  14. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/980406
推荐阅读
相关标签
  

闽ICP备14008679号