-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem383.py
More file actions
26 lines (25 loc) · 796 Bytes
/
problem383.py
File metadata and controls
26 lines (25 loc) · 796 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
# <---coding: utf-8--->
# @Time: 2022/4/14/11:33
# @Author = posiondy
# @Email: 1547590574@qq.com
# @Software: PyCharm
class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
a, b = len(ransomNote), len(magazine)
if a > b:
return False
if a <= b :
map = {}
for i, j in enumerate(magazine):
map[j] = map[j] + 1 if j in map.keys() else 1
for i, item in enumerate(ransomNote):
if item not in map:
return False
else:
if map[item] >= 1:
map[item] -= 1
else:
return False
return True
s = Solution()
print(s.canConstruct('aa','aab'))