https://leetcode.com/PRoblems/reverse-linked-list/
/** * 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) { if (head == NULL) return NULL; if (head->next == NULL) return head; ListNode *pNode = head; ListNode *pre = NULL; while( pNode ) { ListNode *pnext = pNode->next; pNode->next = pre; pre = pNode; pNode = pnext; } return pre; } };
新闻热点
疑难解答