Two Sum - Difference equals to target
ID: 610; medium
Solution 1 (Java)
Notes
Two pointers
i
andj
We move the
i
pointer in this solution to narrow down the range of the two numbers.Time complexity:
O(n)
Space complexity:
O(1)
Solution 2 (Java)
Notes
This solution is also the two pointers method, but we move the j pointer. We make sure that j is always larger than i, so we do not need to check for the increasing order in the final answer.
Time complexity:
O(n)
Space complexity:
O(1)
Last updated