且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将两个已排序的数组合并为一个已排序的数组?

更新时间:2023-11-23 11:31:16

一个小改进,但是在主循环之后,您可以使用 System.arraycopy 复制任一输入数组的尾部到达另一个的尽头.不过,这不会改变您的解决方案的 O(n) 性能特征.

A minor improvement, but after the main loop, you could use System.arraycopy to copy the tail of either input array when you get to the end of the other. That won't change the O(n) performance characteristics of your solution, though.