[LeetCode]题解(python):092-Reverse Linked List II
2015-12-30 14:59
573 查看
[b]题目来源:[/b]
https://leetcode.com/problems/reverse-linked-list-ii/
[b]题意分析:[/b]
跟定一个链表,和位置m,n。将m到n的节点翻转。
[b]题目思路:[/b]
和前面全部翻转的类似。
[b]代码(Python):[/b]
View Code
转载请注明出处:/article/6365032.html
https://leetcode.com/problems/reverse-linked-list-ii/
[b]题意分析:[/b]
跟定一个链表,和位置m,n。将m到n的节点翻转。
[b]题目思路:[/b]
和前面全部翻转的类似。
[b]代码(Python):[/b]
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def reverseBetween(self, head, m, n): """ :type head: ListNode :type m: int :type n: int :rtype: ListNode """ if head == None or head.next == None: return head ans = ListNode(-1) t,ans.next = ans,head for i in range(m - 1): t = t.next tmp = t.next for i in range(n- m): tmp1 = t.next t.next = tmp.next tmp.next = tmp.next.next t.next.next = tmp1 return ans.next
View Code
转载请注明出处:/article/6365032.html
相关文章推荐
- Python 文件I/O (转)
- [LeetCode]题解(python):091-Decode Ways
- SublimeText3 安装和配置,以及配置 Python 环境
- Python 功能和特点(新手必学)
- [LeetCode]题解(python):090-Subsets II
- python 安装pillow
- [LeetCode]题解(python):089-Gray Code
- python多线程
- python--文件处理范例
- [LeetCode]题解(python):088-Merge Sorted Array
- Python标准库10 多进程初步 (multiprocessing包)
- 笨方法学Python(11-15)
- Use Visual studio 2010 build Python2.7.10
- [LeetCode]题解(python):086-Partition List
- [LeetCode]题解(python):083-Remove Duplicates from Sorted List
- [LeetCode]题解(python):082-Remove Duplicates from Sorted List II
- Python标准库09 当前进程信息 (os包)
- [LeetCode]题解(python):081-Search in Rotated Sorted Array II
- [LeetCode]题解(python):080-Remove Duplicates from Sorted Array II
- Python 2.1 函数的调用