383 Ransom Note 赎金信
给定一个赎金信 (ransom) 字符串和一个杂志(magazine)字符串,判断第一个字符串ransom能不能由第二个字符串magazines里面的字符构成。如果可以构成,返回 true ;否则返回 false。
(题目说明:为了不暴露赎金信字迹,要从杂志上搜索各个需要的字母,组成单词来表达意思。)
注意:
你可以假设两个字符串均只含有小写字母。
canConstruct("a", "b") -> false
canConstruct("aa", "ab") -> false
canConstruct("aa", "aab") -> true
详见:https://leetcode.com/problems/ransom-note/description/
C++:
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
unordered_map<char,int> m;
for(char c:magazine)
{
++m[c];
}
for(char c:ransomNote)
{
if(--m[c]<0)
{
return false;
}
}
return true;
}
};
383 Ransom Note 赎金信的更多相关文章
- 383. Ransom Note【easy】
383. Ransom Note[easy] Given an arbitrary ransom note string and another string containing letters f ...
- leetcode 383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all th ...
- 383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all th ...
- leetcode修炼之路——383. Ransom Note
题目是这样的 Given an arbitrary ransom note string and another string containing letters from a ...
- 14. leetcode 383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, ...
- [LeetCode&Python] Problem 383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, ...
- Java [Leetcode 383]Ransom Note
题目描述: Given an arbitrary ransom note string and another string containing letters from al ...
- 383. Ransom Note 在字典数组中查找笔记数组
[抄题]: Given an arbitrary ransom note string and another string containing letters from all the magaz ...
- LeetCode: 383 Ransom Note(easy)
题目: Given an arbitrary ransom note string and another string containing letters from all the magazin ...
随机推荐
- poj_2586_Y2K Accounting Bug_201407211318
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10210 Accepted: 50 ...
- 树形DP 树的最小支配集,最小点覆盖与最大独立集
最小支配集: 从V中选取尽量少的点组成一个集合,让V中剩余的点都与取出来的点有边相连. (点) 最小点覆盖: 从V中选取尽量少的点组成一个集合V1,让所有边(u,v)中要么u属于V1,要么v属于V1 ...
- 打开Eclipse出现“An internal error has occurred. java.lang.NullPointerException
今天打开eclipse出现了这个问题:下面是老外给出的办法,粘给大家: Instead of deleting the whole .metadata folder, just delete the ...
- hibernate_Criteria_分页_去重
触发原因:实体类间存在一对多关系,并且在一这方加载多的时候用的加载模式是eager. 解决方法:1.非分页:criteria.setResultTransformer(Criteria.DISTINC ...
- git锁和钩子以及图形化界面
1.锁机制 Locking Options 严格锁(strict locking):一个时刻,只有一个人可以占用资源. 乐观锁(optimistic locking):允许多个人同时修改同一文件.乐观 ...
- 使用Tornado实现http代理
0x00 http代理 http代理的用处非常多,市面上也有公开的代理,可是有时候为了工作须要,比方分析应用层流量.做数据訪问控制.甚至做监控等等.Tornado提供了一些非常方便的环境和API,我们 ...
- 使用RoboCopy 命令[转载]
经常进行文件管理操作的朋友们,不满意于Windows系统内置的复制功能,因为它太龟速了.于是大家就使用FastCopy.TeraCopy之类的软件来加速复制,但是你是否知道Windows 7已经内置快 ...
- JsonArray和JsonObject的使用
import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class JsonTest { public static v ...
- 20160225.CCPP体系具体解释(0035天)
程序片段(01):CircleList.h+CircleList.c+main.c 内容概要:环形链表 ///CircleList.h #pragma once #include <stdio. ...
- 图像处理之基础---基于opencv的灰度图像微分
argv分别为,可执行文件名.读入的原始图像.输出原始图像的灰度值.输出原始图像灰度值沿x轴方向的一阶微分.输出原始图像灰度值沿x轴方向的二阶微分. #include #include #includ ...