【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 non-space characters.
Please note that the string does not contain any non-printable characters.
Example:
- Input: "Hello, my name is John"
- Output: 5
- 找出连续字符串个数(注意示例中Hello,后面有空格)
解题思路:
设立标志位,遍历字符串,当标志位从0变为1时,count++
- int countSegments(char* s) {
- int flag=;
- int i=;
- int count=;
- while(s[i])
- {
- if(!flag&&!(s[i]==' '||s[i]=='\t'))
- {
- flag=;
- count++;
- }
- else
- if(flag&&(s[i]==' '||s[i]=='\t'))
- flag=;
- i++;
- }
- return count;
- }
【LeetCode】434. Number of Segments in a String的更多相关文章
- 【LeetCode】434. Number of Segments in a String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计 正则表达式 字符串分割 日期 题目地址:htt ...
- 【LeetCode】806. Number of Lines To Write String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用ASIIC码求长度 使用字典保存长度 日期 题目 ...
- 【LeetCode】Largest Number 解题报告
[LeetCode]Largest Number 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/largest-number/# ...
- 【LeetCode】792. Number of Matching Subsequences 解题报告(Python)
[LeetCode]792. Number of Matching Subsequences 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
- 【LeetCode】673. Number of Longest Increasing Subsequence 解题报告(Python)
[LeetCode]673. Number of Longest Increasing Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https:/ ...
- 434. Number of Segments in a String
原题: 434. Number of Segments in a String 解题: 刚看到题目时,觉得可以通过统计空格个数,但想想有可能会有多个空格的情况 思路: 一:遍历字符,if条件碰到非空格 ...
- 434. Number of Segments in a String 字符串中的单词个数
[抄题]: Count the number of segments in a string, where a segment is defined to be a contiguous sequen ...
- [LC] 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 ...
- 【LeetCode】Single Number I & II & III
Single Number I : Given an array of integers, every element appears twice except for one. Find that ...
随机推荐
- JavaScript实现360度全景图片展示效果
全景拍摄:所谓“全景拍摄”就是将所有拍摄的多张图片拼成一张全景图片.它的基本拍摄原理是搜索两张图片的边缘部分,并将成像效果最为接近的区域加以重合,以完成图片的自动拼接.现在的智能手机也基本带这个功能. ...
- Jenkins配置和使用
之前整理了Jenkins的下载和安装过程,有需要的可以参考我的博客,地址: http://www.cnblogs.com/luchangyou/p/5981884.html 接下来整理一下Jenk ...
- mac安装lavaral
1,安装composer # brew install josegonzalez/php/composer
- js得到当前页面的url信息方法
js得到当前页面的url信息方法:http://www.cnblogs.com/zuosong160522/p/5755615.html js获取url传递参数,js获取url?后面的参数:http: ...
- linux for 使用
第一种:命令使用方法 例子1: cat test.txt 1 2 3 for i in $(cat test.txt) do echo $i done 例子2: for i in 1 2 3 4 do ...
- fedora22 mysql安装
fedora19以后好像取消了对mysql的支持,看其他人好像说是用的mariadb的.centos里用yum安装的方式,放到fedora中不能用,所以找了很多资料,尝试了一种可行的办法. 在Fedo ...
- Linux Tomcat 自启动
使用chkconfig命令 修改tomcat/bin/startup.sh,在开头的地方添加如下内容 #chkconfig: #description:tomcat auto start #proce ...
- Redis Cluster 实践
一:关于redis cluster 1:redis cluster的现状 reids-cluster计划在redis3.0中推出,可以看作者antirez的声明:http://antirez.com/ ...
- 【转】delphi Format格式化函数
转自:http://www.cnblogs.com/mumble/archive/2011/05/25/2056462.html Format是一个很常用,却又似乎很烦的方法,本人试图对这个方法的帮助 ...
- 矩阵赋值实例(matrixAssign)
题目:给一个二维数组赋值. 分析:主机端代码完成的主要功能: 启动CUDA,使用多卡时应加上设备号,或使用cudaSetDevice()设置GPU设备. 为输入数据分配内存空间 初始化输入数据 为GP ...