File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 1
- from leetcode .editor .en .Q1400 . ConstructKPalindromeStrings import ConstructKPalindromeStrings
1
+ from leetcode .editor .en .Q3223 . MinimumLengthOfStringAfterOperations import MinimumLengthOfStringAfterOperations
2
2
3
3
if __name__ == '__main__' :
4
- print (ConstructKPalindromeStrings ().canConstruct ( s = "eminem" , k = 2 ))
4
+ print (MinimumLengthOfStringAfterOperations ().minimumLength ( "abaacbcbb" ))
You can’t perform that action at this time.
0 commit comments