bumpsoo 2025-06-10 14:23:33 +00:00
parent 74ea899d2c
commit e9aef2c95d

View 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)