/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* cur = head;
ListNode* pre = nullptr;
while (cur != nullptr ) {
ListNode* tmp = cur-> next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre; // cur 最后为 null 退出
}
};
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* cur = head;
ListNode* pre = nullptr;
while (cur != nullptr ) {
ListNode* tmp = cur-> next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre; // cur 最后为 null 退出
}
};
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*//**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*//**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*//**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*//**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*//**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* cur = head;
ListNode* pre = nullptr;
while (cur != nullptr ) {
ListNode* tmp = cur-> next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre; // cur 最后为 null 退出
}
};
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* cur = head;
ListNode* pre = nullptr;
while (cur != nullptr ) {
ListNode* tmp = cur-> next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre; // cur 最后为 null 退出
}
};
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* cur = head;
ListNode* pre = nullptr;
while (cur != nullptr ) {
ListNode* tmp = cur-> next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre; // cur 最后为 null 退出
}
};
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* cur = head;
ListNode* pre = nullptr;
while (cur != nullptr ) {
ListNode* tmp = cur-> next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre; // cur 最后为 null 退出
}
};
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* cur = head;
ListNode* pre = nullptr;
while (cur != nullptr ) {
ListNode* tmp = cur-> next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre; // cur 最后为 null 退出
}
};
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* cur = head;
ListNode* pre = nullptr;
while (cur != nullptr ) {
ListNode* tmp = cur-> next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre; // cur 最后为 null 退出
}
};
*/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* cur = head;
ListNode* pre = nullptr;
while (cur != nullptr ) {
ListNode* tmp = cur-> next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre; // cur 最后为 null 退出
}
};
ListNode* reverseList(ListNode* head) {
ListNode* cur = head;
ListNode* pre = nullptr;
while (cur != nullptr ) {
ListNode* tmp = cur-> next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre; // cur 最后为 null 退出
}
};
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* cur = head;
ListNode* pre = nullptr;
while (cur != nullptr ) {
ListNode* tmp = cur-> next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre; // cur 最后为 null 退出
}
};
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* cur = head;
ListNode* pre = nullptr;
while (cur != nullptr ) {
ListNode* tmp = cur-> next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre; // cur 最后为 null 退出
}
};