版权声明:原创勿转 https://cloud.tencent.com/developer/article/1412977
思路
暴力破解
code
代码语言:javascript复制func countSegments(s string) int {
count := 1
found := false
for i := 0; i < len(s); i {
if i > 0 && s[i] == ' ' && s[i-1] != ' ' {
count
}
if s[i] != ' ' {
found = true
}
if i == len(s)-1 && s[i] == ' ' {
count--
}
}
if found {
return count
}
return 0
}