diff options
| -rw-r--r-- | misc/cards/main.rb | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/misc/cards/main.rb b/misc/cards/main.rb index a44fcc4..075a3b1 100644 --- a/misc/cards/main.rb +++ b/misc/cards/main.rb @@ -35,13 +35,16 @@ class Solution # space: O(n) ? def run(row) cards = row.split + cache = Hash.new do |hash, key| + hash[key] = Card.new(key) + end for i in (0...cards.size) - x = Card.new(cards[i]) + x = cache[cards[i]] for p in (i+1...cards.size) - y = Card.new(cards[p]) + y = cache[cards[p]] for q in (p+1...cards.size) - z = Card.new(cards[q]) + z = cache[cards[q]] if x.match?(y, z) return [x, y, z].map(&:to_s).join(' ') end @@ -51,9 +54,6 @@ class Solution "" end - - private - end assert_equal(true, Card.new("+C").match?(Card.new("-CC"), Card.new("=CCC"))) |
