LeetCode Two Sum
Problem Description Link: https://leetcode.com/problems/two-sum/description/
Accepted Solution
/*
I have tried to avoid the solution with O(N^2). Therefore, I found the difference (x) between the target and current value and eventually checked whether x is present in the array or not. If it is, then the current position (i) and the last position ind[nums[i]] would be the answer. However, if both the current value and x are similar, in that case, you have to check the value that exists in the array multiple times.
The complexity of the solution in O(N).
*/
Comments
Post a Comment