How to write an algorithm to check if the sum of any two numbers in an array/list matches a given number?

前端 未结 14 1974
萌比男神i
萌比男神i 2021-01-30 11:29

How can I write an algorithm to check if the sum of any two numbers in an array/list matches a given number with a complexity of nlogn?

14条回答
  •  旧巷少年郎
    2021-01-30 12:06

    Depends If you want only one sum O(N) or O(N log N) or all sums O(N^2) or O(N^2 log N). In the latter case better uses an FFT>

提交回复
热议问题