# Definition for singly-linked list.# class ListNode:# def __init__(self, val=0, next=None):# self.val = val# self.next = nextclassSolution:defreverseList(self,head: ListNode) -> ListNode:ifnot head ornot head.next:return head last = self.reverseList(head.next) head.next.next = head head.next =Nonereturn last