美文网首页
383. Ransom Note

383. Ransom Note

作者: 安东可 | 来源:发表于2018-04-11 22:33 被阅读16次

    383. Ransom Note

    【思路】

    • 字符统计问题,使用map
        bool canConstruct(string ransomNote, string magazine) {
           
                    
            unordered_map<char, int> 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

          本文链接:https://www.haomeiwen.com/subject/yihtkftx.html