Commit 5c20f1f

mo <mokha@cisco.com>
2017-06-09 02:35:19
shorten my original solution.
1 parent 06845a0
Changed files (1)
spec/sum_of_two_spec.rb
@@ -41,11 +41,7 @@ describe "sum_of_two" do
   # time: nlogn
   def sum_of_two(a, b, v)
     outer, inner =  a.size > b.size ? [b.sort, a.sort] : [a.sort, b.sort]
-    outer.each do |i|
-      target = v - i
-      return true if inner.bsearch { |x| target <=> x }
-    end
-    false
+    outer.any? { |i| inner.bsearch { |x| (v - i) <=> x } }
   end
 
   # time: n