https://leetcode.com/problems/maximum-number-of-words-you-can-type/
package main
import (
"strings"
)
func main() {
text := "leet code"
brokenLetters := "lt"
canBeTypedWords(text, brokenLetters)
}
// 제출 코드
func canBeTypedWords(text string, brokenLetters string) int {
textArray := strings.Split(text, " ")
brokenLettersArray := strings.Split(brokenLetters, "")
typedWords := len(textArray)
for _, v := range textArray {
sign := false
for _, s := range brokenLettersArray {
if strings.Contains(v, s) {
if sign == true {
continue
}
typedWords -= 1
sign = true
}
}
}
return typedWords
}
'Algorithm > Go' 카테고리의 다른 글
[Leetcode] Single Number (0) | 2021.12.20 |
---|---|
[Leetcode] Majority Element (0) | 2021.12.19 |
[Leetcode] Final Value of Variable After Performing Operations (0) | 2021.12.12 |
[LeetCode] Consecutive Characters (Go) (0) | 2021.12.06 |
[Leetcode] Two Sum (Go) (0) | 2021.12.06 |