Leetcode Note: Go - Maximum Number of Words You Can Type
Maximum Number of Words You Can Type - LeetCode
https://leetcode.com/problems/maximum-number-of-words-you-can-type/
- Go 言語で取り組んだメモ
回答
Go easy - Maximum Number of Words You Can Type - LeetCode
https://leetcode.com/problems/maximum-number-of-words-you-can-type/solutions/2131952/go-easy/
func canBeTypedWords(text string, brokenLetters string) int {
broken := make(map[byte]bool)
for i := 0; i < len(brokenLetters); i++ {
broken[brokenLetters[i]] = true
}
res, words := 0, strings.Split(text, " ")
for _, word := range words {
fully := true
for i := 0; i < len(word); i++ {
if broken[word[i]] {
fully = false
break
}
}
if fully {
res++
}
}
return res
}