Skip to content

Commit

Permalink
1046
Browse files Browse the repository at this point in the history
  • Loading branch information
TedTran2019 committed Jul 8, 2022
1 parent e8592e8 commit 9e93ab7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ruby/1046-Last-Stone-Weight.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rubygems'
require 'algorithms'
include Containers

def last_stone_weight(stones)
heap = MaxHeap.new
stones.each { |stone| heap << stone }
until heap.size <= 1
stone1 = heap.pop
stone2 = heap.pop
heap << (stone1 - stone2).abs if stone1 != stone2
end
last = heap.pop
last.nil? ? 0 : last
end

0 comments on commit 9e93ab7

Please sign in to comment.