# -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def ReverseList(self, pHead): if pHead is None: return last=None while pHead is not None: tmp=pHead.next pHead.next=last last=pHead pH…
[python]Leetcode每日一题-反转链表 II [题目描述] 给你单链表的头节点 head 和两个整数 left 和 right ,其中 left <= right .请你反转从位置 left 到位置 right 的链表节点,返回 反转后的链表 . 示例1: 输入:head = [1,2,3,4,5], left = 2, right = 4 输出:[1,4,3,2,5] 示例2: 输入:head = [5], left = 1, right = 1 输出:[5] 提示: 链表中节点数…