mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-14 16:14:52 +08:00
add: leetcode 0434 solution
This commit is contained in:
@ -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
|
||||
}
|
Reference in New Issue
Block a user