Skip to content

Commit

Permalink
leet code 961 ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
sharawatankit committed Oct 10, 2019
1 parent 7e4a3e4 commit 6f5eda9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions leet_961.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://leetcode.com/problems/N-Repeated Element in Size 2N Array/
# Runtime: 48 ms, faster than 81.88% of ruby online submissions for N-Repeated Element in Size 2N Array
def repeated_n_times(a)
ans = Hash.new(0)
a.each do |k|
if ans[k] > 1
return k
else
ans[k] +=1
end
end
return ans.max_by{|k,v| v}[0]
end

0 comments on commit 6f5eda9

Please sign in to comment.