# [383\. Ransom Note](https://leetcode.com/problems/ransom-note/) :::spoiler Solution ```cpp class Solution { public: bool canConstruct(string ransomNote, string magazine) { vector<int> freq(26); for(auto& c : magazine) ++freq[ c - 'a']; for(int i = 0; i < ransomNote.size(); i++) { int c = ransomNote[i] - 'a'; if (--freq[c] < 0) return false; } return true; } }; ``` - T: $O(N)$ - S: $O(1)$ :::
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up