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

leetcode434的更多相关文章

  1. 每天一道LeetCode--434. Number of Segments in a String

    Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...

  2. [Swift]LeetCode434. 字符串中的单词数 | Number of Segments in a String

    Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...

  3. leetcode434 字符串中的单词树(python)

    统计字符串中的单词个数,这里的单词指的是连续的不是空格的字符. 请注意,你可以假定字符串里不包括任何不可打印的字符. 示例: 输入: "Hello, my name is John" ...

  4. Leetcode434.Number of Segments in a String字符串中的单词数

    统计字符串中的单词个数,这里的单词指的是连续的不是空格的字符. 请注意,你可以假定字符串里不包括任何不可打印的字符. 示例: 输入: "Hello, my name is John" ...

随机推荐

  1. vue全家桶实现笔记本功能

    一个通过vue实现的练手小项目,数据保存和导出通过node进行处理 成品截图: 安装vue-cli,webpack: cnpm install webpack -g cnpm install vue- ...

  2. UVA-1605 Building for UN (构造)

    题目大意:n个国家的人要在一栋大厦里办公,要求任意两个国家的办公室要相邻(同层同边或邻层同面),设计一个满足要求的方案. 题目分析:题目限制较少,任意构造出一个解即可. 代码如下: # include ...

  3. c++ 中的 set

    set (集合) 中的元素是排序好的,而且是不重复的. 例题:hdu 4989 题目大意:求一组数列中任意两个不重复元素和,再求不重复和的和. #include <bits/stdc++.h&g ...

  4. 聊聊一直困扰前端程序员的浏览器兼容-【JavaScript】

    上篇已经写过浏览器的兼容发展历史以及主流浏览器,主要的css兼容我知道的已全部写到,这篇这篇专攻javascript的兼容. 1.getYear()方法 var year = new Date().g ...

  5. h5桌面通知Notification

    H5中的桌面通知Notification 前言: 对于一个前端开发者,逛网页总会留意一些新奇的功能,对于上班总会用到Teambition的我,总是能收到Notification...所以今天就来研究下 ...

  6. oracle修改约束列

    Oracle 增加修改删除字段 添加字段的语法:alter table tablename add (column datatype [default value][null/not null],-. ...

  7. bzoj3862

    题解: 这一道题目和模板有不同的地方就是在于可以修改只有一条边和i相邻 于是我们还要记录与这个点相邻的点有没有改变 代码: #pragma GCC optimize(2) #include<bi ...

  8. hdu5818

    题解: 维护两个左偏树 按照左偏树模板来做 代码: #include<cstdio> #include<cmath> #include<algorithm> #in ...

  9. 201621123006 《Java程序设计》第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 2. 书面作业 本次作业题集集合 List中指定元素的删除(题集题目) 1.1 实验总结.并回答:列举至少2种 ...

  10. Alpha阶段贡献分配规则

    作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2244] 分配规则: 1.每人有基础分3分. 2.每参加一次组内会议及活动加0. ...