class Solution(object):
def reverseBetween(self, head, m, n):
"""
:type head: ListNode
:type m: int
:type n: int
:rtype: ListNode
"""
node=head
prenode=node
for i in xrange(1,m):
prenode=node
node=node.next
lnode=node
rnode=node.next
bottonnode=lnode
for i in xrange(m,n):
nextnode=rnode.next
rnode.next=lnode
lnode=rnode
rnode=nextnode
if bottonnode!=None:
prenode.next=lnode
bottonnode.next=rnode
if m==1:
head=lnode
return head