| https://leetcode.com/problems/number-of-segments-in-a-string | Easy |
|---|
fun countSegments(s: String): Int {
var count = 0
var inSegment = false
for (char in s) {
if (char != ' ') {
if (!inSegment) {
count++ // Новый сегмент начался
inSegment = true
}
} else {
inSegment = false // Конец сегмента
}
}
return count
}