LeetCode[206] Reverse Linked List

来源:互联网 发布:人格训练软件 编辑:程序博客网 时间:2024/04/27 19:49

Reverse a singly 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) {ListNode *h = NULL;while (head) {ListNode *now = head;head = head->next;now->next = h;h = now;}return h;}};

0 0