# 383. Ransom Note

#### Easy

***

Given two strings `ransomNote` and `magazine`, return `true` *if* `ransomNote` *can be constructed by using the letters from* `magazine` *and* `false` *otherwise*.

Each letter in `magazine` can only be used once in `ransomNote`.

&#x20;

**Example 1:**

<pre><code>Input: ransomNote = "a", magazine = "b"
<strong>Output:
</strong> false
</code></pre>

**Example 2:**

<pre><code>Input: ransomNote = "aa", magazine = "ab"
<strong>Output:
</strong> false
</code></pre>

**Example 3:**

<pre><code>Input: ransomNote = "aa", magazine = "aab"
<strong>Output:
</strong> true
</code></pre>

&#x20;

**Constraints:**

* `1 <= ransomNote.length, magazine.length <= 105`
* `ransomNote` and `magazine` consist of lowercase English letters.

```python
class Solution:
    def canConstruct(self, ransomNote: str, magazine: str) -> bool:
        counterA = self.getDict(ransomNote)
        counterB = self.getDict(magazine)
        for key in counterA.keys():
            if counterB[key] < counterA[key]:
                return False
        return True
    
    def getDict(self, s: str):
        d = defaultdict(int)
        for char in list(s):
            d[char] += 1
        return d
```
