Commit 9e4990c

mo <mokha@cisco.com>
2017-06-09 02:24:04
add implementation using hash.
1 parent 4527b79
Changed files (1)
spec/sum_of_two_spec.rb
@@ -47,6 +47,12 @@ describe "sum_of_two" do
     false
   end
 
+  def sum_of_two(a, b, v)
+    hash = {}
+    a.each { |x| hash[x] = true }
+    b.any? { |x| hash[v - x] }
+  end
+
   [
     { a: [1, 2, 3], b: [10, 20, 30, 40], v: 42, expected: true },
     { a: [1, 2, 3], b: [10, 20, 30, 40], v: 50, expected: false },