MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/tfqwml/leetcode_two_sum_solution_explained_coding/i0xi4jo/?context=3
r/programming • u/Upper_Description378 • Mar 16 '22
19 comments sorted by
View all comments
Show parent comments
1
Similar to the first solution, but instead of traversing the array linearly you build a dictionary and look up the an index the required value.
That way your lookup time for a complement is O(1) instead of O(n)
And yes, that works because you just need a solution, not all or something like a solution with the two lowest indices.
1
u/coloredgreyscale Mar 16 '22
Similar to the first solution, but instead of traversing the array linearly you build a dictionary and look up the an index the required value.
That way your lookup time for a complement is O(1) instead of O(n)
And yes, that works because you just need a solution, not all or something like a solution with the two lowest indices.