美文网首页
java算法--合并两个链表

java算法--合并两个链表

作者: android_coder | 来源:发表于2021-04-27 23:28 被阅读0次

主要思路是递归

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算法--合并两个链表

      本文链接:https://www.haomeiwen.com/subject/ywflrltx.html