- Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathencrypt-and-decrypt-strings.py
More file actions
Latest commit
26 lines (19 loc) · 840 Bytes
/
Copy pathencrypt-and-decrypt-strings.py
File metadata and controls
26 lines (19 loc) · 840 Bytes
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
# 2227. Encrypt and Decrypt Strings
# https://leetcode.com/problems/encrypt-and-decrypt-strings/
classEncrypter:
def__init__(self, keys: List[str], values: List[str], dictionary: List[str]):
self.back=dict()
self.keys=keys
self.values=values
self.dictionary=dictionary
fori, keyinenumerate(keys):
self.back[key] =i
self.ddict=Counter(self.encrypt(d) fordinself.dictionary)
defencrypt(self, word1: str) ->str:
return''.join(self.values[self.back[i]] foriinword1)
defdecrypt(self, word2: str) ->int:
returnself.ddict[word2]
# Your Encrypter object will be instantiated and called as such:
# obj = Encrypter(keys, values, dictionary)
# param_1 = obj.encrypt(word1)
# param_2 = obj.decrypt(word2)