Two sum: Difference between revisions
Content added Content deleted
(add RPL) |
|||
Line 1,055: | Line 1,055: | ||
i = 1 |
i = 1 |
||
j = len array[] |
j = len array[] |
||
# The array remains empty if no sum is found |
|||
pair[] = [ ] |
pair[] = [ ] |
||
repeat |
repeat |
||
if array[i] + array[j] = sum |
if array[i] + array[j] = sum |
||
pair[] = [ i j ] |
pair[] = [ i j ] |
||
return |
|||
elif array[i] + array[j] > sum |
elif array[i] + array[j] > sum |
||
j -= 1 |
j -= 1 |
||
Line 1,070: | Line 1,069: | ||
. |
. |
||
numbers[] = [ 0 2 11 19 90 ] |
numbers[] = [ 0 2 11 19 90 ] |
||
twoSum 21 numbers[] pair[] |
|||
print |
print pair[] |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>[2 |
<pre>[ 2 4]</pre> |
||
=={{header|Elixir}}== |
=={{header|Elixir}}== |