Commit 0a3e551

mo khan <mo.khan@gmail.com>
2020-08-18 22:02:26
Reduce # of lines
1 parent 8844865
Changed files (1)
2020
08
2020/08/18/main.rb
@@ -6,13 +6,10 @@ class Solution
   # time: O(n)
   # space: O(n)
   def self.run(items)
-    cache = Hash.new do |hash, key|
-      hash[key] = 2
-    end
+    cache = Hash.new { |h, k| h[k] = 2 }
 
-    for i in (0...items.size)
-      item = items[i]
-      cache[item] -= 1
+    for i in items
+      cache[i] -= 1
     end
 
     cache.values.find { |value| value > 0 }
@@ -20,3 +17,4 @@ class Solution
 end
 
 assert_equal 1, Solution.run([4, 3, 2, 4, 1, 3, 2])
+puts 'Yay!'