Jump to content

Two sum: Difference between revisions

m
Line 2,119:
So… I initially misread the task as "return the two integers" and then realised it was "…the indices of…", but that's OK — it just meant writing an extra word to find the indices, given the numbers.
 
The last three lines of <code>task</code> are in case the two integers found by <code>twosometwosum</code> are equal - in which case, as <code>find</code> finds the first instance in the array and the array is sorted, we can safely take the index plus one as the second index.
 
<lang Quackery> [ 0 peek ] is first ( [ --> n )
1,462

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.