Jump to content

Two sum: Difference between revisions

8 bytes removed ,  2 years ago
Updated to work with Nim 1.4. Also minor formatting changes.
m (→‎version 2: used a better comment.)
(Updated to work with Nim 1.4. Also minor formatting changes.)
Line 1,363:
 
=={{header|Nim}}==
<lang nim>proc twoSum (src : openarray[int], target : int ) : array[2, int] =
if src.len < 2:
return
 
for base in 0 .. (src.len - 2):
for ext in (base + 1) .. < src.len:
if (src[base] + src[ext]) == target:
result[0] = base
result[1] = ext
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.