add: leetcode 0434 solution

This commit is contained in:
tphyhFighting
2021-10-07 19:28:26 +08:00
parent f461eadb78
commit bde069b75e
3 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package leetcode
func countSegments(s string) int {
segments := false
cnt := 0
for _, v := range s {
if v == ' ' && segments {
segments = false
cnt += 1
} else if v != ' ' {
segments = true
}
}
if segments {
cnt++
}
return cnt
}