【剑指Offer学习】【面试题17 ::合并两个排序的链表】

https://blog.csdn.net/derrantcm/article/details/46678155

与合并两个有序数组一个思想 
       // 当两个链表都不为空就进行合并操作
        while (head1 != null && head2 != null) {
            // 下面的操作合并较小的元素
            if (head1.value < head2.value) {
                pointer.next = head1;
                head1 = head1.next;
            } else {
                pointer.next = head2;
                head2 = head2.next;
            }

            // 将指针移动到合并后的链表的末尾
            pointer = pointer.next;
        }
发布了81 篇原创文章 · 获赞 68 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/li198847/article/details/104442865
今日推荐