# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: # @param head, a ListNode # @param m, an integer # @param n, an integer # @return a ListNode def reverseBetween(self, head, m, n): if not head: return None before=ListNode(0) before.next=head fast=slow=head for i in range(m-1): before=slow slow=slow.next for i in range(n-1): fast=fast.next for i in range(n-m): before.next=slow.next slow.next=fast.next fast.next=slow slow=before.next return before.next if m==1 else head
Friday, September 12, 2014
Leetcode: Reverse Linked List II @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment