Thursday, December 22, 2022
A function to determine if ransomNote
can be constructed by using the letters from magazine
, each of them is used only once.
import "strings"
func canConstruct(ransomNote string, magazine string) bool {
for _, rune := range ransomNote {
frequencyInRansomNote := strings.Count(ransomNote, string(rune))
frequencyInMagazine := strings.Count(magazine, string(rune))
if (frequencyInMagazine < frequencyInRansomNote) {
return false
}
}
return true
}