单链表翻转(图解)
目录
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode *ReverseList(struct ListNode *head)
{
struct ListNode *prev = NULL;
struct ListNode *curr = NULL;
while(head != NULL)
{
curr = head->next;
head->next = prev;
prev = head;
head = curr;
}
return prev;
}
作者:mayicoder
链接:https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/solution/cyu-yan-xian-fan-zhuan-zai-shi-yong-wei-i5bi5/
来源:力扣(LeetCode)