mycode   98.87

# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def reverseList(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        last = None
        while head:       
            new_head = head.next 
            head.next = last
            last = head
            head = new_head
        return last

 

相关文章:

  • 2021-12-16
  • 2021-06-24
  • 2021-12-15
  • 2022-02-05
  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-07
  • 2021-07-21
  • 2021-06-13
  • 2021-12-06
  • 2021-08-30
  • 2021-08-20
  • 2021-10-13
相关资源
相似解决方案