java算法--合并两个链表

主要思路是递归

public static Node mergeListNode(Node first, Node two) {
        if (first == null) {
            return two;
        }
        if (two == null) {
            return first;
        }
        Node head = null;
        if (first.value <= two.value) {
            head = first;
            head.next = mergeListNode(first.next, two);
        } else {
            head = two;
            head.next = mergeListNode(first, two.next);
        }
        return head;
    }

你可能感兴趣的:(java算法--合并两个链表)