-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimumDeletions.py
40 lines (35 loc) · 1001 Bytes
/
minimumDeletions.py
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
33
34
35
36
37
38
39
40
from calendar import c
from re import A
from tkinter import E
class Solution(object):
def minDeletions(self, s):
"""
:type s: str
:rtype: int
"""
num_array = [0] * (len(s) + 1)
char_dict = {}
deletes = 0
for char in s:
if char in char_dict:
char_dict[char] += 1
else:
char_dict[char] = 1
print(char_dict)
for char in char_dict:
num_array[char_dict[char]] += 1
print(num_array)
for i, num in enumerate(reversed(num_array)):
if num > 1 and i < len(num_array):
index = len(num_array) - i - 1
num_array[index - 1] += num_array[index] - 1
print(num_array)
deletes += num_array[index] - 1
print(index)
print(deletes)
return deletes
Solution().minDeletions("aaabbbc")
# bbbb
# c
# e
# a