383. Ransom Note 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011121314class Solution {public: bool canConstruct(string ransomNote, string magazine) { int n = ransomNote.size(), m = magazine.size(); if(n>m) return false; vector<int> vec(26,0); for(char c:magazine) vec[c-'a']++; for(char c:ransomNote){ vec[c-'a']--; if(vec[c-'a']<0) return false; } return true; }}; analysis time complexity O(n) space complexity O(1)