383. Ransom Note

383. Ransom Note

【思路】

  • 字符统计问题,使用map
    bool canConstruct(string ransomNote, string magazine) {
       
                
        unordered_map map;
        for (int i = 0; i < magazine.size(); ++i)
            ++map[magazine[i]];
        for (int j = 0; j < ransomNote.size(); ++j)
            if (--map[ransomNote[j]] < 0)
                return false;
        return true; 
    }

你可能感兴趣的:(383. Ransom Note)