forked from sashaaero/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e4a3e4
commit 6f5eda9
Showing
1 changed file
with
13 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |