55 / 205
LeetCode · EasyOson10 ball· ~5 daqiqa

Maximum Number of Words Found in Sentences

Sizga satrlar massivi sentences berilgan. Har bir element so'zlari orasida bo'sh joy bo'lgan bitta gapni bildiradi.

Jamlangan so'zlar bo'yicha eng ko'p so'z qatnashgan gapni topib, uning ichidagi so'zlar sonini qaytaring.

example.go
func solve(sentences []string) int {
    // ...
}

Misollar

kod
Input: sentences = ["alice and bob love leetcode", "i think so too", "this is great thanks very much"]
Output: 6
Tushuntirish:
1-gap: 5 so'z
2-gap: 4 so'z
3-gap: 6 so'z. Maksimal so'zlar soni 6 ga teng.
kod
Input: sentences = ["please wait", "continue to fight", "continue to win"]
Output: 3
kod
Input: sentences = ["a"]
Output: 1
kod
Input: sentences = ["a b c", "d e", "f g h i"]
Output: 4

Maslahatlar

  1. Har bir gapdagi so'zlar sonini bo'sh joylar bo'yicha ajratib sanashni o'ylang.
  2. Har bir gapni bo'sh joy bo'yicha bo'laklarga ajrating (masalan, strings.Fields), hosil bo'lgan bo'laklar sonini hisoblang va barcha gaplar ichidan eng kattasini saqlab boring.