What is the most efficient way of merging [1,2] and [7,8] into [[1,7], [2,8]]

前端 未结 4 1763
囚心锁ツ
囚心锁ツ 2021-01-13 15:43

Given 2 arrays [1,2] and [7,8] what is the most efficient way of merging that to form [[1,7], [2,8]]. I know we can do this:

a1 = [1,2], a2 = [7,8], a3=[];
f         


        
4条回答
  •  耶瑟儿~
    2021-01-13 16:36

    There is no way to do this faster than O(n) because every element must be touched once.

提交回复
热议问题