Two sum: Difference between revisions
Content deleted Content added
→{{header|zkl}}: another solution |
→{{header|zkl}}: sort arrays |
||
Line 80:
=={{header|zkl}}==
I think this is O(n!), The double loop solution is O(n^2). These two solutions don't care if the array is sorted
<lang zkl>fcn twoSum(sum,ns){
Utils.Helpers.combosKW(2,ns).filter('wrap([(a,b)]){ a+b==sum }) // lazy combos
Line 92:
rs
}</lang>
<lang zkl>twoSum(21,T(0,2,11,19
twoSum(25,T(0,2,11,19
{{out}}
<pre>
L(L(0,
L()
</pre>
|