We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
You are correct for the complexity, however no need for a dictionnary here, a set does the trick. Also, you can do this in one iteration over the collection by adding the numbers to the set incrementally and checking if the complement was already present in the set. Something like this:
Pairs
You are viewing a single comment's thread. Return to all comments →
You are correct for the complexity, however no need for a dictionnary here, a set does the trick. Also, you can do this in one iteration over the collection by adding the numbers to the set incrementally and checking if the complement was already present in the set. Something like this: