-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add solution and test-cases for problem 3005
- Loading branch information
Showing
3 changed files
with
42 additions
and
23 deletions.
There are no files selected for viewing
29 changes: 15 additions & 14 deletions
29
leetcode/3001-3100/3005.Count-Elements-With-Maximum-Frequency/README.md
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
23 changes: 21 additions & 2 deletions
23
leetcode/3001-3100/3005.Count-Elements-With-Maximum-Frequency/Solution.go
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 |
---|---|---|
@@ -1,5 +1,24 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
func Solution(nums []int) int { | ||
count := make([]int, 101) | ||
for _, n := range nums { | ||
count[n]++ | ||
} | ||
|
||
ans := 0 | ||
freq := -1 | ||
for _, c := range count { | ||
if c == 0 { | ||
continue | ||
} | ||
if c > freq { | ||
ans = 0 | ||
freq = c | ||
} | ||
if c == freq { | ||
ans += freq | ||
} | ||
} | ||
return ans | ||
} |
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