This commit is contained in:
parent
74ea899d2c
commit
e9aef2c95d
1 changed files with 16 additions and 0 deletions
16
easy/maximum_difference_between_even_and_odd_frequency_i.py
Normal file
16
easy/maximum_difference_between_even_and_odd_frequency_i.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# https://leetcode.com/problems/maximum-difference-between-even-and-odd-frequency-i
|
||||
|
||||
from typing import Counter
|
||||
|
||||
class Solution:
|
||||
def maxDifference(self, s: str) -> int:
|
||||
c = Counter(s)
|
||||
max_odd = float("-inf")
|
||||
min_even = float("inf")
|
||||
for k in c:
|
||||
if c[k] % 2 == 1:
|
||||
max_odd = max(max_odd, c[k])
|
||||
else:
|
||||
min_even = min(min_even, c[k])
|
||||
return int(max_odd - min_even)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue