[LeetCode]--383. Ransom Note


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

我的想法是用map记录两边的字母表的每一个字母的个数,然后判断ransomNote里面字母肯定都要包含在magazine里面,而且个数要比它少。

public boolean 
Leetcode 383 Ransom Note lc383 Ransom Note 两个for 第一个记录sourse字符串每种字母出现次数 第二个看现有字母是否能够填满target 1 class Solution { 2 public boolean canConstruct(String ransomNote, String magazine) { 3 if(ransomNote.len... 阅读详情

相关推荐

LeetCode 383. Ransom Note

[Easy] LeetCode 383. Ransom Note 链接: https://leetcode.com/problems/ransom-note/ 题目描述: Given an arbitrary ransom note string and another string containing letters from all the magazines, write a funct...

MrJustin的博客 203

【力扣题解】383. Ransom Note

从杂志中剪切字母构造匿名信

weixin_43603839的博客 262

Leetcode383. Ransom Note

题目地址: https://leetcode.com/problems/ransom-note/ 给定两个字符串,问第一个字符串可否由第二个字符串的字符构成(次数也要考虑)。 直接数一下即可。代码如下: public class Solution { public boolean canConstruct(String ransomNote, String magazine) { int[] mchs = new int[26]; for (int i = 0; i

数学、算法爱好者的博客 486

LeetCode 383. Ransom Note 题解(C++)

Given
 an 
arbitrary
 ransomnotestring 
and 
another 
string 
containing 
letters from
 all 
the 
magazines,
 write 
a 
function 
that 
will 
return 
true 
if 
the 
ransomnote 
can 
be 
constructed 
from

prayyojay的博客 1128

NYUer | LeetCode383 Ransom Note

NYUer | LeetCode383 Ransom Note

Moses_SU的博客 190

[leetcode] 383. Ransom Note

Given
 an 
arbitrary
 ransomnotestring 
and 
another 
string 
containing 
letters from
 all 
the 
magazines,
 write 
a 
function 
that 
will 
return 
true 
if 
the 
ransomnote 
can 
be 
constru

TstsUgeg的博客 1732

LeetCode 383 Ransom Note

Problem: Given
 an 
arbitrary
 ransomnotestring 
and 
another 
string 
containing 
letters from
 all 
the 
magazines,
 write 
a 
function 
that 
will 
return 
true 
if 
the 
ransomnote 
c...

dilian4850的博客 602

[LeetCode]383. Ransom Note

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 magazi

DannieZ的博客 343

LeetCode:383 Ransom Note

383. Ransom Note>Given
 an
arbitrary
 ransomnotestring 
and 
another
 string 
containing 
letters from
 all
the
magazines

Wisimer 2858

leetcode383. Ransom Note

一、题目描述 
Given
 an 
arbitrary
 ransomnotestring 
and 
another 
string 
containing 
letters from
 all 
the 
magazines,
 write 
a 
function 
that 
will 
return 
true 
if 
the 
ransomnote 
can

小拳头的博客 628

leetcode_383 Ransom Note

题目分析给定两个字符串magazines和ransomNote,判断是否可以从magazines中抽取字母(每个字母只能用一次)组成ransomNote。字符串均由小写字母组成。 解题思路1)统计ransomNote中每个字符出现的次数; 2)然后统计magazines中字符出现的次数; 3)判断ransomNote中的字符是否全部包含在magazines中即可。 实现程序 bool canCo

没有最好,只有更好! 916

LeetCode383 Ransom Note(java)

原题 题目要求 解法 原题Given
 an 
arbitrary
 ransomnotestring 
and 
another 
string 
containing 
letters from
 all 
the 
magazines,
 write 
a 
function 
that 
will 
return 
true 
if 
the 
ransomnote 
can

添经地翼的博客 7087

leetcode 383. Ransom Note

【代码】leetcode 383. Ransom Note

weixin_41554427的博客 327

leetcode: 383. Ransom Note

leetcode: 383. Ransom Note 原题链接 class Solution { public: bool canConstruct(string ransomNote, string magazine) { int mp[26] = {0}; for (char x : magazine) mp[x - 'a']++; for (char x : ransomNote) { if (m

LSK的博客 278

LeetCode_383. Ransom Note

383. Ransom Note: 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

DatingLi的博客 393

LeetCode //C - 383. Ransom Note

【代码】LeetCode //C - 383. Ransom Note

Made in Code 377

LeetCode String 383. Ransom Note

383. Ransom Note 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 t...

Yi Jiao's Blog 178
上一篇: [LeetCode]--374. Guess Number Higher or Lower
下一篇: [LeetCode]--387. First Unique Character in a String
杜鲁门
博客等级 码龄11年 219粉丝 316原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值