206.反转链表

难度:简单
题目描述:
206.反转链表_第1张图片
思路总结:明天媳妇就来了,正好两道简单题,直接做了完事,回来总结下近一个月左右做的Tree的题,回顾之前的字符串和数组的题。
题解一:

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

class Solution:
    def reverseList(self, head: ListNode) -> ListNode:
        pre = None
        while head:
            tmp = head.next
            head.next = pre
            pre = head
            head = tmp
        return pre

题解一结果:
206.反转链表_第2张图片

你可能感兴趣的:(朱滕威的面试之路)