public class Solution {
public int CountSegments(string s) {
s = s.Trim();
if (s.Length == )
{
return ;
}
else
{
var whitespacecount = ;
var prewhiteindex = -;
for (int i = ; i < s.Length; i++)
{
var c = s[i];
if (char.IsWhiteSpace(c))
{
if (prewhiteindex + != i)
{
whitespacecount++;
}
prewhiteindex = i;
}
}
return whitespacecount + ;
}
}
}
https://leetcode.com/problems/number-of-segments-in-a-string/#/description