in reply to Re^4: LeetCode Problem #1 - Two Sum - Improve and/or discuss.
in thread LeetCode Problem #1 - Two Sum - Improve and/or discuss.
> Please post whatever parts of the code you'd write differently.
my @tests = ( [[2,7,11,15], 9, [0,1]], [[3,2,4], 6, [1,2]], [[3,3], 6, [0,1]], ); for my $test (@tests) { is_deeply sort_arrayref(two_sum($test->[INPUT], $test->[TARGET])), $test->[EXPECTED]; } sub sort_arrayref { my ($aref) = @_; return [ sort { $a <=> $b } @$aref ]; }
hope it's clearer now :)
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: LeetCode Problem #1 - Two Sum - Improve and/or discuss.
by kcott (Archbishop) on Jan 24, 2022 at 21:36 UTC | |
by LanX (Saint) on Jan 24, 2022 at 22:13 UTC | |
by kcott (Archbishop) on Jan 25, 2022 at 01:17 UTC |