Skip to content

Commit 4e56391

Browse files
committed
130125
1 parent bb4b315 commit 4e56391

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import collections
2+
3+
4+
# leetcode submit region begin(Prohibit modification and deletion)
5+
class Solution:
6+
def minimumLength(self, s: str) -> int:
7+
lmap = collections.defaultdict(collections.deque)
8+
N = len(s)
9+
for i in range(N):
10+
c = s[i]
11+
lmap[c].append(i)
12+
for i in range(26):
13+
c = chr(i + ord('a'))
14+
while len(lmap[c]) > 2:
15+
lmap[c].popleft()
16+
lmap[c].pop()
17+
remaining = []
18+
for c, idxs in lmap.items():
19+
while idxs:
20+
remaining.append((idxs.popleft(), c))
21+
return len(remaining)
22+
# remaining.sort()
23+
# ans = []
24+
# for _, c in remaining:
25+
# ans.append(c)
26+
# return len(ans)
27+
28+
29+
# leetcode submit region end(Prohibit modification and deletion)
30+
31+
32+
class MinimumLengthOfStringAfterOperations(Solution):
33+
pass

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from leetcode.editor.en.Q1400.ConstructKPalindromeStrings import ConstructKPalindromeStrings
1+
from leetcode.editor.en.Q3223.MinimumLengthOfStringAfterOperations import MinimumLengthOfStringAfterOperations
22

33
if __name__ == '__main__':
4-
print(ConstructKPalindromeStrings().canConstruct(s="eminem", k=2))
4+
print(MinimumLengthOfStringAfterOperations().minimumLength("abaacbcbb"))

0 commit comments

Comments
 (0)