"be consistent" | |
PerlMonks |
Re: LeetCode Problem #1 - Two Sum - Improve and/or discuss.by NetWallah (Canon) |
on Jan 24, 2022 at 03:35 UTC ( [id://11140770]=note: print w/replies, xml ) | Need Help?? |
I did not benchmark this yet - but this should be faster (it passes your tests):
UPDATE 1: removed buggy " -1" from (0..$#$inp -1); deleted unnecessary variable @solutions.
UPDATE 2: I did try to benchmark the code - kcott's runs ~ 40% faster, so I was surprised! kcott's code fails that test case, but mine passes. Note - that new test case does meet the problem definition (array of integers), which can have negative numbers. Also - kcott's code assumes and takes advantage of the input being sorted - input order is NOT specified in the problem definition. BTW - thanks for setting up this challenge! "If you had better tools, you could more effectively demonstrate your total incompetence."
In Section
Seekers of Perl Wisdom
|
|