Encrypt and Decrypt Strings LeetCode solution in Python

1
class Encrypter:
2

3
def __init__(self, keys: List[str], values: List[str], dictionary: List[str]):
4
self.hashmap = dict()
5
for i in range(len(keys)):
6
self.hashmap[keys[i]] = values[i]
7
self.dictmap = defaultdict(int)
8
for word in dictionary:
9
self.dictmap[self.encrypt(word)] += 1
10

11
def encrypt(self, word1: str) -> str:
12
output = ""
13
for char in word1:
14
output += self.hashmap[char]
15
return output
16

17
def decrypt(self, word2: str) -> int:
18
return self.dictmap[word2]

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0