LeetCode : Ransom Note
来源:互联网 发布:茶叶网络连锁 编辑:程序博客网 时间:2024/06/09 23:56
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; otherwise, it will return false.
Each letter in the magazine string can only be used once in your ransom note.
Note:
You may assume that both strings contain only lowercase letters.
canConstruct(“a”, “b”) -> false
canConstruct(“aa”, “ab”) -> false
canConstruct(“aa”, “aab”) -> true
class Solution {public: bool canConstruct(string ransomNote, string magazine) { int countM[256] = {0}; int countR[256] = {0}; if(ransomNote.size()>magazine.size()) return false; for(int i=0;i<magazine.length();++i) { countM[magazine[i]]++; } for(int k = 0;k<ransomNote.length();++k) { countR[ransomNote[k]]++; } for(int j = 0;j<256;++j) { if(countM[j]<countR[j]) return false; } return true; }};
0 0
- leetcode-383. Ransom Note
- [leetcode] 383. Ransom Note
- LeetCode:383 Ransom Note
- 【Leetcode】Ransom Note
- LeetCode 383. Ransom Note
- Leetcode Ransom Note
- LeetCode#383 Ransom Note
- leetcode 383. Ransom Note
- leetcode 383. Ransom Note
- LeetCode: Ransom Note
- LeetCode Ransom Note(字符串)
- 383.[LeetCode]Ransom Note
- leetcode 383. Ransom Note
- leetcode 383. Ransom Note
- Leetcode 383. Ransom Note
- [Leetcode]Ransom Note
- [LeetCode] Ransom Note (java)
- LeetCode 383 Ransom Note
- use generator and co in mocha
- nfs部署和优化
- [BZOJ2540]ctsc2000快乐的蜜月(dp+归并排序)
- 【Codeforces 777 C Alyona and Spreadsheet】
- ListView源码分析(二)
- LeetCode : Ransom Note
- 元素为指针的vector的使用说明
- Java8系列之重新认识HashMap
- Node中require()的原理
- 一道蓝桥杯题对于处理输入的启发
- poj3168(扫描线)
- LICEcap方便快捷制作gif图片的工具
- 412. Fizz Buzz
- drawableTop,button图片显示在文字上面,文字不显示的问题