z_zhaojun的博客

Reverse a linked list from position m to n. Do it in-place and in one-pass.

For example:
Given 1->2->3->4->5->NULL, m = 2 and n = 4,

return 1->4->3->2->5->NULL.

Note:
Given m, n satisfy the following condition:
1 ≤ m ≤ n ≤ length of list.

/**
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) { val = x; }
* }
*/
public class Solution {
ListNode listNode = null;
if (listNode != null) {
node.next = listNode;
}
listNode = node;
}
return listNode;
}

public ListNode reverseBetween(ListNode head, int m, int n) {
ListNode lNode;
ListNode mNode;
ListNode rNode;
boolean hasL = true;
if (m == 1) {
hasL = false;
}
n -= m;
while (--m > 1) {
}
if (hasL) {
} else {
}
if (mNode == null) {
return lNode;
}
ListNode temp;
temp = mNode;
while (n-- > 0) {
temp = temp.next;
}
rNode = temp.next;
temp.next = null;
mNode = reverseList(mNode);
if (hasL) {
} else {
}
while (mNode.next != null) {
mNode = mNode.next;
}
mNode.next = rNode;
if (hasL) {
return lNode;
}
}
}

Reverse Linked List II -- LeetCode

2014-04-28 04:58:33

2015-05-16 14:28:52

2014-12-05 15:59:28

2016-02-19 13:39:20

leetCode练习（92）

2016-10-25 10:19:13

2014-01-28 01:06:19

2014-01-28 11:06:09

PAT 02-线性结构3 Reversing Linked List 【JAVA实现】

2016-10-25 12:03:15

2015-08-16 20:13:06