目录
一题目:
二代码:
三结果:
一题目:
给你单链表的头节点 head
,请你反转链表,并返回反转后的链表。
二代码:
/*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/
struct ListNode* reverseList(struct ListNode* head) {if(head==NULL||head->next==NULL){return head;}struct ListNode* new_head=reverseList(head->next);head->next->next=head;head->next=NULL;return new_head;
}