leetcode Ransom Note

leetcode 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.

题目地址:leetcode Ransom Note

题目大意:给定两个字符串magazines和ransomNote,问是否可以从magazines中抽取字母(每个字母只能用一次)组成ransomNote

思路:只要判断ransomNote字符是不是全部在magazines中即可,用hash。。 水

C++

Java

Python

 

 

本题是leetcode 383 Ransom Note 的题解

更多题解可以查看:https://www.hrwhisper.me/leetcode-algorithm-solution/

 

本博客若无特殊说明则由 hrwhisper 原创发布
转载请点名出处:细语呢喃 > leetcode Ransom Note
本文地址:https://www.hrwhisper.me/leetcode-ransom-note/

打赏一杯咖啡钱呗

Leetcode , , , , . permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *