标签:leetcode public solution 练习 示例 ini head ble https
反转一个单链表。
示例:
输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->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 *new_head = NULL; while(head) { ListNode *next = head->next; head->next = new_head; new_head=head; head=next; } return new_head; } };
标签:leetcode public solution 练习 示例 ini head ble https
原文地址:https://www.cnblogs.com/KID-XiaoYuan/p/12217352.html