反转链表 -- 每日一题05
''' 先取出第一个节点,置空next,取名为tail 然后依次取出节点,将取出节点的next指向tail,然后tail调至取出的节点 ''' class Solution: def ReverseList(self , head: ListNode) -> ListNode: # write code here if head == None or head.next==None: return head tail = head # 先将head地址换了 head = head.next tail.next = None while head is not None: temp = head.next head.next = tail tail = head head = temp return tail