aboutsummaryrefslogtreecommitdiff
path: root/count_element_max_freq.py
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-09-21 21:23:03 -0600
committerJack Sangdahl <[email protected]>2025-09-21 21:23:03 -0600
commit844c8a0bbcb890ec4ddd5ef485b767b00b44a78f (patch)
tree635f16d8808748730c842902eee8aacfaf25fefe /count_element_max_freq.py
parent448f4ccf6dd4d89a1348be3092fee4340bc70206 (diff)
downloadleetcode-844c8a0bbcb890ec4ddd5ef485b767b00b44a78f.tar.gz
leetcode-844c8a0bbcb890ec4ddd5ef485b767b00b44a78f.zip
3005. count elements with maximum frequency
Diffstat (limited to 'count_element_max_freq.py')
-rw-r--r--count_element_max_freq.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/count_element_max_freq.py b/count_element_max_freq.py
index 5c8e6b2..57e8cf2 100644
--- a/count_element_max_freq.py
+++ b/count_element_max_freq.py
@@ -14,16 +14,14 @@ class Solution(object):
:type nums: List[int]
:rtype: int
"""
- u_map = {}
+ freq = [0] * 101
+ max_freq, ans = 0, 0
for i in nums:
- u_map[i] = u_map.get(i, 0) + 1
- max_i = 0
- for key, val in u_map.items():
- max_i = max(max_i, val)
- ans = 0
- for key, val in u_map.items():
- if val == max_i:
- ans += val
+ freq[i] += 1
+ max_freq = max(max_freq, freq[i])
+ for i in freq:
+ if i == max_freq:
+ ans += i
return ans