16 lines
460 B
Python
16 lines
460 B
Python
# 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)
|
|
|