A recursive algorithm to find two integers in an array that sums to a given integer

后端 未结 8 1060
Happy的楠姐
Happy的楠姐 2021-01-16 19:36

I need an algorithm to determine if an array contains two elements that sum to a given integer.

The array is sorted.

The algorithm should be recursiv

8条回答
  •  时光说笑
    2021-01-16 20:03

    Sort the array. Search for the complement of each number (sum-number). Complexity O(nlogn).

提交回复
热议问题