mirror of
https://git.wolves.top/wolves/leetcode.git
synced 2025-11-05 01:36:32 +08:00
init
This commit is contained in:
28
23/08/24.cpp
Normal file
28
23/08/24.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include "lists.h"
|
||||
|
||||
class Q24 {
|
||||
public:
|
||||
ListNode *swapPairs(ListNode *head) {
|
||||
if (!head || !head->next) {
|
||||
return head;
|
||||
}
|
||||
ListNode *p1;
|
||||
ListNode *p2;
|
||||
p1 = head;
|
||||
p2 = head->next;
|
||||
|
||||
while (!p2){
|
||||
p1->next = p2->next;
|
||||
p2->next = p1;
|
||||
|
||||
if(!p1->next){
|
||||
return head;
|
||||
}
|
||||
|
||||
p1 = p1->next;
|
||||
p2 = p1->next;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user