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 ...
随机推荐
- UVA 437_The Tower of Babylon
题意: 一堆石头,给定长宽高,每种石头均可以使用无数次,问这堆石头可以叠放的最高高度,要求下面的石头的长和宽分别严格大于上面石头的长和宽. 分析: 采用DAG最长路算法,由于长宽较大,不能直接用于表示 ...
- cogs——619. [金陵中学2007] 传话
619. [金陵中学2007] 传话 ★★ 输入文件:messagez.in 输出文件:messagez.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 兴趣小 ...
- ppc_85xx-gcc -shared -fPIC liberr.c -o liberr.so
fPIC作用于编译阶段,告诉编译器产生与位置无关代码(Position-Independent Code), 则产生的代码中,没有绝对地址,所有使用相对地址.故而代码能够被载入器载入到内存的随意 ...
- 实战恢复2950交换机的IOS
本来想用两台交换机做实验的,可是通过console口进入其中一台交换机后却发现这个台交换器的IOS文件丢失了 本来正常进入交换机后应该是首先进入到用户模式的,而且提示符应该是">&qu ...
- CCNA参考链接
http://www.cisco.com/c/en/us/support/docs/lan-switching/vtp/10558-21.html http://www.cisco.com/c/en/ ...
- 启用Mac系统读写NFTS磁盘
从Mac OSX 10.6系统开始苹果系统已经内置对NTFS写入功能,但苹果没有公开说明,而且在默认状态下是没有开启的.SL-NTFS是一款Mac上的小工具,它可以直接为你的Mac增加NTFS的写入权 ...
- [React] Build a slide deck with mdx-deck using Markdown + React
In this lesson we'll use mdx-deck to create a slide deck using Markdown and React. We'll look at add ...
- 笔记本能连上WIFI网络,但是无法上网怎么办
在插网线的台式机上登陆192.168.1.1,点击无线设置,修改一下SSID号,别的什么都不用改. 然后保存,需要重启路由器.重启之后再用笔记本连接新的无线网络即可.
- jquery中怎样防止冒泡事件
jquery中怎样防止冒泡事件 1.利用event.stopPropagation() 2.利用return false 3.利用event.preventDefault()
- 用py文件调用操作系统的命名,粘包问题
帅爆太阳的男人 1,执行代码 在py代码中去调用操作系统的命令 新的模块:subprocess, import subprocess r = subprocess().Popen( "dir ...