原题
https://leetcode.cn/problems/ransom-note/
解法
记录下字母出现次数
func canConstruct(ransomNote string, magazine string) bool {
var letterCount [26]int
for _, c := range magazine{
letterCount[int(c-'a')] += 1
}
for _, c := range ransomNote{
letterCount[int(c-'a')] -= 1
if letterCount[int(c-'a')]<0{
return false
}
}
return true
}
原创文章,作者:彭晨涛,如若转载,请注明出处:https://www.codetool.top/article/leetcode383-%e8%b5%8e%e9%87%91%e4%bf%a1/