public static ListNode mergeTwoLists(ListNode first, ListNode second) {
        if (first == null || second == null) {
            return first == null ? second : first;
        }

        ListNode head, tmp;

        if (first.val <= second.val) {
            head = first;
            first = first.next;
        } else {
            head = second;
            second = second.next;
        }
        tmp = head;


        while (first != null && second != null) {
            if (first.val <= second.val) {
                tmp.next = first;
                tmp = first;
                first = first.next;
            } else {
                tmp.next = second;
                tmp = second;
                second = second.next;
            }
        }

        if (first != null) {
            tmp.next = first;
        }
        
        if (second != null) {
            tmp.next = second;
        }

        return head;
    }