查询 O(n) 增删改O(1)
21. 合并有序链表

class Solution {public ListNode mergeTwoLists(ListNode l1, ListNode l2) {if (l1 == null) return l2;if (l2 == null) return l1;if (l1.val < l2.val) {l1.next = mergeTwoLists(l1.next, l2);return l1;} else {l2.next = mergeTwoLists(l1, l2.next);return l2;}}}
24. 两两交换链表中的节点

class Solution {public ListNode swapPairs(ListNode head) {if (head == null || head.next == null)return head;ListNode n = head.next;head.next = swapPairs(n.next);n.next = head;return n;}}
25. K个一组翻转链表

class Solution {//递归public ListNode reverseKGroup(ListNode head, int k) {ListNode curr = head;int count = 0;while (curr != null && count != k) {curr = curr.next;count++;}if (count == k) {curr = reverseKGroup(curr, k);while (count-- > 0) {ListNode tmp = head.next;head.next = curr;curr = head;head = tmp;}head = curr;}return head;}}
141. 环形链表

public class Solution {public boolean hasCycle(ListNode head) {if (head == null || head.next == null)return false;ListNode low = head;ListNode fast = head;while (fast.next != null && fast.next.next != null) {low = low.next;fast = fast.next.next;if (low == fast) return true;}return false;}}
142. 环形链表二

public class Solution {public ListNode detectCycle(ListNode head) {Set<ListNode> set = new HashSet<>();while (head != null) {if (set.contains(head)) return head;set.add(head);head = head.next;}return null;}}
206. 反转链表

class Solution {public ListNode reverseList(ListNode head) {ListNode newHead = null;while (head != null) {ListNode next = head.next;head.next = newHead;newHead = head;head = next;}return newHead;}}

