Determine whether or not there exist two elements in Set S whose sum is exactly x - correct solution?

后端 未结 8 2105
醉梦人生
醉梦人生 2020-12-04 19:48

Taken from Introduction to Algorithms

Describe a Θ(n lg n)-time algorithm that, given a set S of n integers and another integer x, determines whet

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 20:00

    Your analysis is correct, and yes you must sort the array or else binary search does not work.

提交回复
热议问题