Skip to content

[STR4] add most frequent char #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add most frequent char v4
  • Loading branch information
Agatha Bahati committed Feb 27, 2023
commit e7e2a8cbe9f267ea2186521ee69181b71c44a1b3
9 changes: 9 additions & 0 deletions most-frequent-char/most_frequent_char_v4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from collections import Counter

def most_frequent_char(s):
tracker = Counter(s)
proxy = None
for char in s:
if proxy is None or tracker[char] > tracker[proxy]:
proxy = char
return proxy