public static ListNode reverseBetween(ListNode head, int m, int n) {
ListNode pre=head,current=head,mPre = new ListNode(0),mNode = new ListNode(0),nNode = new ListNode(0),temp;
mPre.next=head;
int i=1;
while(i<=n)
{
if(i==m-1)
mPre=current;
if(i==m)
mNode=current;
if(i==n)
nNode=current;
if(m<i&&i<=n)
{
temp=current;
current=current.next;
temp.next=pre;
pre=temp;
}
else{
pre=current;
current=current.next;
}
i++;
}
mPre.next=nNode;
mNode.next=current;
if(m==1)
return nNode;
else
return head; }
相关文章
- Leetcode Linked List Cycle II
- Linked List Cycle II--寻找单链表中环的起始点
- Reverse Linked List II java
- Singly linked list algorithm implemented by Java
- 【LeetCode】206. Reverse Linked List 解题报告(Python&C++&java)
- LeetCode 141. Linked List Cycle 判断链表是否有环 C++/Java
- leetcode 203. Remove Linked List Elements 、83. Remove Duplicates from Sorted List 、82. Remove Duplicates from Sorted List II(剑指offer57 删除链表中重复的结点)
- 【leetcode】Reverse Linked List(easy)
- LeetCode 206 Reverse a singly linked list.
- lc面试准备:Reverse Linked List II