标签:str val http int 链表 init nod return href
利用双指针算法,直接让后面一个指向前面一个
/**
* 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* p = NULL;
ListNode* q = head;
while(q != NULL){
ListNode* r = q->next;
q->next = p;
p = q, q = r;
}
return p;
}
};
标签:str val http int 链表 init nod return href
原文地址:https://www.cnblogs.com/Lngstart/p/13336629.html