默写 翻转单链表(lc92)

class Solution{

ListNode succeeder=null;

public ListNode reverse(ListNode head){

if(head==null||head.next=0){return head;}

ListNode last=reverse(head.next);

head.next.next=head;

head.next=null;

 

return last;

 

}

public reverseN(ListNode head,int n){

if(n==1)

{succeeder=head.next;

return head;}

ListNode last=reverseN(head.next,n-1);

head.next.next=head;

head.next=succeeder;

return last;

}

public reverseMN(ListNode head,int m,int n){

if(m==1)

return reversN(head,n);

 

head.next=reverseMN(head.next,m-1,n-1);

return head;

 

 

}

}

posted on 2022-09-26 23:21  somedieyoung-navi  阅读(13)  评论(0编辑  收藏  举报