3 ms·
If you're computing the hash-table ahead of time you only need to do n+k. If you're setting the value in the hash table as you check it (as you would in a sing
by ohyes 9y ago
If you're computing the hash-table ahead of time you only need to do n+k.
If you're setting the value in the hash table as you check it (as you would in a single pass), you have to do n-k as well.
This is because the number you are currently adding didn't exist in the array when you checked n+k for the previous numbers.