##### 1. 去重单链表中出现两次及以上的所有节点

https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/

``````// AC: Runtime: 1 ms, faster than 27.17% of Java online submissions for Remove Duplicates from Sorted List II.
// Memory Usage: 38.6 MB, less than 34.10% of Java online submissions for Remove Duplicates from Sorted List II.
// .
// T:O(n), S:O(n)
//
class Solution {
public ListNode deleteDuplicates(ListNode head) {
HashSet<Integer> dup = new HashSet<>();
int prev = Integer.MIN_VALUE;
while (headCopy != null) {
if (headCopy.val == prev) {
}
}

while (headCopy2 != null && headCopy2.next != null) {
} else {
}
}
// handle the head pointer itself
if (headCopy2 != null && dup.contains(headCopy2.val)) {
return null;
}
prevNode.next = null;
}

}
}
``````
##### 2.链表拼接：

``````// AC: Runtime: 1 ms, faster than 100.00% of Java online submissions for Merge In Between Linked Lists.
// Memory Usage: 42.8 MB, less than 72.32% of Java online submissions for Merge In Between Linked Lists.
// record the cut start nodes and end nodes, and concatenate them to the list2
// T:O(m + n), S:O(1)
//
class Solution {
public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
ListNode head = list1, list1Start, list1End;
int aCopy = a;
// move to the prev node by the nodes cut first.
while (aCopy-- > 1) {
list1 = list1.next;
}
list1Start = list1;
// move the the end nodes after cut [a,b]
int length = b - a + 2;
while (length-- > 0) {
list1Start = list1Start.next;
}
list1End = list1Start;

list1.next = list2;
// move list2 to its end, the point to list1's cut end node.
while (list2.next != null) {
list2 = list2.next;
}
list2.next = list1End;

}
}
``````
##### 3.链表累加和

``````// AC: Runtime: 2 ms, faster than 98.16% of Java online submissions for Add Two Numbers II.
// Memory Usage: 39.3 MB, less than 68.00% of Java online submissions for Add Two Numbers II.
// first reverse, then accumulate the two numbers. Notice that the answer is reversed output, that is high bit is in the front.
// T:O(n), S:O(n)
//
class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
ListNode start1 = reverseList(l1), start2 = reverseList(l2), retHead;
List<Integer> ret = new ArrayList<>();
int forwarding = 0;
while (start1 != null || start2 != null) {
int bit1 = 0, bit2 = 0;
if (start1 != null) {
bit1 = start1.val;
start1 = start1.next;
}
if (start2 != null) {
bit2 = start2.val;
start2 = start2.next;
}
if (bit1 + bit2 + forwarding >= 10) {
ret.add((bit1 + bit2 + forwarding) % 10);
forwarding = 1;
} else {
ret.add(bit1 + bit2 + forwarding);
forwarding = 0;
}
}
if (forwarding > 0) {
}
retHead = new ListNode(ret.get(ret.size() - 1));
ListNode copy = retHead;
for (int i = ret.size() - 2; i >= 0; i--) {
ListNode next = new ListNode(ret.get(i));
copy.next = next;
copy = next;
}

}

private ListNode reverseList(ListNode head) {
ListNode prev = null, temp = head;
while (head != null) {
}

return prev;
}
}
``````
##### 4.leetcode328-将链表奇数位和偶数位分开排列再相连

``````// AC: Runtime: 0 ms, faster than 100.00% of Java online submissions for Odd Even Linked List.
// Memory Usage: 38.6 MB, less than 60.27% of Java online submissions for Odd Even Linked List.
// divide the original linked-list into odd-list and even-list, and concat even-list to end of odd-list.
// T:O(n), S:O(1)
//
class Solution {
public ListNode oddEvenList(ListNode head) {
if (head != null) {
while (even != null && even.next != null) {
odd.next = odd.next.next;
even.next = even.next.next;
odd = odd.next;
even = even.next;
}
}