in reply to LeetCode Problem #1 - Two Sum - Improve and/or discuss.

Hello kcott and thanks for this amusement

The test is more complex than the code if you want to accept both [0,1] and [1,0] better and easier just rely on the expected sum. Anyway..

sub two_sum_Discipulus { my ($input, $target) = @_; foreach my $index ( 0 .. $#$input ){ ( $_ != $index and $input->[$_] + $input->[$index] == $target +) ? return [$index, $_] + : 0 for 0 .. $#$input; } }

PS added newlines for a minimal readability enhancement

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.