Skip to content

Commit ec16f58

Browse files
author
Gonzalo Diaz
committed
[BUGFIX] wrong type hinting fixed. Clean code improvement.
1 parent 6569d18 commit ec16f58

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
# @link Problem definition
22
# [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.md]]
33

4-
from typing import Dict
4+
from typing import Dict, List
55

66
__YES__ = 'Yes'
77
__NO__ = 'No'
88

99

10-
def check_magazine_compute(magazine: str, note: str) -> bool:
10+
def check_magazine_compute(magazine: List[str], note: List[str]) -> bool:
1111
dictionary: Dict[str, int] = {}
1212

13-
for x in magazine:
13+
word: str
1414

15-
if x in dictionary:
16-
dictionary[x] += 1
15+
for word in magazine:
16+
17+
if word in dictionary:
18+
dictionary[word] += 1
1719
else:
18-
dictionary[x] = 1
20+
dictionary[word] = 1
1921

20-
for x in note:
22+
for word in note:
2123

22-
if x in dictionary and dictionary[x] > 0:
23-
dictionary[x] -= 1
24+
if word in dictionary and dictionary[word] > 0:
25+
dictionary[word] -= 1
2426
else:
2527
return False
2628

2729
return True
2830

2931

30-
def check_magazine(magazine: str, note: str) -> str:
32+
def check_magazine(magazine: List[str], note: List[str]) -> str:
3133
return __YES__ if check_magazine_compute(magazine, note) else __NO__

0 commit comments

Comments
 (0)