https://leetcode-cn.com/problems/merge-two-sorted-lists/

    • 简单题,有限几个变量搞定 ```java public static ListNode mergeTwoLists(ListNode l1, ListNode l2) { if (l1 == null) return l2; if (l2 == null) return l1; ListNode head; if (l1.val <= l2.val) {
      1. head = l1;
      2. l1 = l1.next;
      } else {
      1. head = l2;
      2. l2 = l2.next;
      } ListNode cur = head; while (l1 != null && l2!= null) {
      1. if (l1.val <= l2.val) {
      2. cur = cur.next = l1;
      3. l1 = l1.next;
      4. } else {
      5. cur = cur.next = l2;
      6. l2 = l2.next;
      7. }
      } if (l1 == null) {
      1. cur.next = l2;
      } if (l2 == null) {
      1. cur.next = l1;
      } return head; }

    public static class ListNode { int val; ListNode next; ListNode() {} ListNode(int val) { this.val = val; } ListNode(int val, ListNode next) { this.val = val; this.next = next; } }

    ```