-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
40 lines (38 loc) · 893 Bytes
/
Copy pathmain.cpp
File metadata and controls
40 lines (38 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// main.cpp
// leetcode024
//
// Created by 萧天牧 on 17/2/27.
// Copyright © 2017年 萧天牧. All rights reserved.
//
#include <iostream>
using namespace std;
struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};
ListNode* swap(ListNode* A,ListNode* B){
if(B == NULL)
return A;
A->next = B -> next;
B->next = A;
return B;
}
ListNode* swapPairs(ListNode* head) {
if(head == NULL || head -> next == NULL)
return head;
ListNode *shaobing = new ListNode(0);
shaobing ->next = head;
ListNode *tmp = shaobing;
while(tmp && tmp->next){
tmp -> next = swap(tmp ->next, tmp -> next -> next);
tmp = tmp ->next -> next;
}
return shaobing->next;
}
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}