Leetcode Note: Go - Maximum Number of Words Found in Sentences

Maximum Number of Words Found in Sentences - LeetCode
https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/

  • Go 言語で取り組んだメモ

回答

{Go} Simple and concise solution without string splitting - Maximum Number of Words Found in Sentences - LeetCode
https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/solutions/3007639/go-simple-and-concise-solution-without-string-splitting/

func mostWordsFound(sentences []string) int {

    result := 0

    for i := range sentences {
        numberOfWords := strings.Count(sentences[i], " ") + 1
        
        if  numberOfWords > result {
            result = numberOfWords
        }
    }

    return result 
}