/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @return ListNode类
*/
typedef struct ListNode ListNode;
struct ListNode* ReverseList(struct ListNode* head ) {
// write code here
if(head==NULL){
return head;
}
ListNode* n1=NULL;
ListNode* n2=head;
ListNode* n3=head->next;
while(n2){
n2->next=n1;
n1=n2;
n2=n3;
n3=n3->next;
}
return n1;
}

京公网安备 11010502036488号