blob: d9f4dd777877a38ac5ad0db570507510a66ab992 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# 3223. Minimum Length of String After Operations
from collections import Counter
"""
you are given a string 's'. you can perform the following process on 's' any
number of times: choose an index 'i' in the string such that there is at
least one character to the left of index 'i' that is equal to 's[i]' and at
least one character to the right that is also equal to 's[i]', delete the
closest character to the left of index 'i' that is equal to 's[i]', delete
the closest character to the right of index 'i' that is equal to 's[i]'.
return the minimum length of the final string 's' that you can achieve
"""
class Solution(object):
def minimumLength(self, s):
"""
:type s: str
:rtype: int
"""
map, ans = Counter(s), 0
for c, cnt in map.items():
ans += 1
if not cnt % 2:
ans += 1
return ans
if __name__ == "__main__":
obj = Solution()
print(obj.minimumLength("abaacbcbb"))
print(obj.minimumLength("aa"))
|