-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathransomNote.py
More file actions
39 lines (36 loc) · 908 Bytes
/
ransomNote.py
File metadata and controls
39 lines (36 loc) · 908 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
27
28
29
30
31
32
33
34
35
36
37
38
def ransom_note(magazine, ransom):
### Iterative Method
"""
mag = magazine#[item.lower() for item in magazine]
ransom = ransom#[item.lower() for item in ransom]
n = len(ransom)
match = 0
for word in ransom:
if word in mag:
mag.remove(word)
match += 1
if match == n:
return True
else:
return False
"""
### Dictionary Method
mag = {}
for word in magazine:
if word not in mag:
mag[word] = 0
mag[word] += 1
for word in ransom:
if mag[word] == 0 or word not in mag:
return False
else:
mag[word] -= 1
return True
m, n = map(int, raw_input().strip().split(' '))
magazine = raw_input().strip().split(' ')
ransom = raw_input().strip().split(' ')
answer = ransom_note(magazine, ransom)
if(answer):
print "Yes"
else:
print "No"