From 8d5f40d02b9a01912b95843c3b3fdc0c1872be54 Mon Sep 17 00:00:00 2001 From: Mhrooz Date: Fri, 24 May 2024 23:28:39 +0200 Subject: [PATCH] pass 383 easy --- 383-240524-pass/main.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 383-240524-pass/main.py diff --git a/383-240524-pass/main.py b/383-240524-pass/main.py new file mode 100644 index 0000000..00a7fca --- /dev/null +++ b/383-240524-pass/main.py @@ -0,0 +1,27 @@ +class Solution: + def canConstruct(self, ransomNote: str, magazine: str) -> bool: + ran_dic = {} + mag_dic = {} + for l in ransomNote: + if l not in ran_dic: + ran_dic[l] = 1 + else: + ran_dic[l] += 1 + for l in magazine: + if l not in mag_dic: + mag_dic[l] = 1 + else: + mag_dic[l] += 1 + print(ran_dic) + print(mag_dic) + for key in ran_dic: + if key not in mag_dic: + return False + if ran_dic[key] > mag_dic[key]: + return False + return True + +sol = Solution() +print(sol.canConstruct("a", "b")) +print(sol.canConstruct("aa", "ab")) +print(sol.canConstruct("aa", "aab")) \ No newline at end of file