master
1def assert(x)
2 raise x.inspect unless x
3end
4
5class Solution
6 # time: O(n)
7 # space: O(n)
8 def self.run(items, k)
9 nums = {}
10
11 for i in (0...items.size)
12 nums[items[i]] = true
13 return true if nums[k - items[i]]
14 end
15
16 false
17 end
18end
19=begin
20 h
21|4|7|1|-3|2|
22=end
23
24assert(Solution.run([4, 7, 1, -3, 2], 5))
25assert(!Solution.run([], 5))
26assert(!Solution.run([1], 5))
27assert(Solution.run([1,-3,7,8], 5))
28assert(Solution.run([3,1,3], 6))
29puts "Yay!"