728x90
반응형
문제풀이
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
unordered_map<char,int> um1,um2;
for(int i=0;i<ransomNote.size();i++)
um1[ransomNote[i]]++;
for(int i=0;i<magazine.size();i++)
um2[magazine[i]]++;
for(int i=0;i<ransomNote.size();i++)
if(um1[ransomNote[i]] > um2[ransomNote[i]])
return false;
return true;
}
};
매거진이 가진 알파벳수보다 랜섬노트가 필요로 하는게 많다면 false
728x90
반응형
'자라는 개발자 > 문제풀이' 카테고리의 다른 글
c++ 백준 27964 콰트로치즈피자 (0) | 2023.05.20 |
---|---|
leetcode 169. Majority ElementEasy (0) | 2023.01.15 |
leetcode 387. First Unique Character in a String (0) | 2022.11.13 |
leetcode 350. Intersection of Two Arrays II (0) | 2022.11.13 |
leetcode 242. Valid Anagram (0) | 2022.11.13 |