力扣206.反转链表
Java版本
class Solution {
public ListNode reverseList(ListNode head) {
if(head==null || head.next==null){
return head;
}
ListNode last=reverseList(head.next);
head.next.next=head;
head.next=null;
return last;
}
}
go版本
func reverseList(head *ListNode) *ListNode {
if head==nil || head.Next==nil{
return head
}
list:=new(ListNode)
list=reverseList(head.Next)
head.Next.Next=head
head.Next=nil
return list
}