Skip to content

Commit 8dcbe5f

Browse files
authored
Create maximum-difference-between-even-and-odd-frequency-i.py
1 parent 2e50525 commit 8dcbe5f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Time: O(n + 26)
2+
# Space: O(26)
3+
4+
# freq table
5+
class Solution(object):
6+
def maxDifference(self, s):
7+
"""
8+
:type s: str
9+
:rtype: int
10+
"""
11+
cnt = [0]*26
12+
for x in s:
13+
cnt[ord(x)-ord('a')] += 1
14+
mn, mx = float("inf"), 0
15+
for x in cnt:
16+
if not x:
17+
continue
18+
if x%2 == 0:
19+
mn = min(mn, x)
20+
else:
21+
mx = max(mx, x)
22+
return mx-mn

0 commit comments

Comments
 (0)