in reply to Re: LeetCode Problem #1 - Two Sum - Improve and/or discuss.
in thread LeetCode Problem #1 - Two Sum - Improve and/or discuss.

O(N log N), O(N) if already sorted.

Rather than sorting the inputs, I would sort the indexes. That way, you wouldn't need an extra hash an array, just an array.

  • Comment on Re^2: LeetCode Problem #1 - Two Sum - Improve and/or discuss.