【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 ...
随机推荐
- 【.NET】SQL链接字符串
第一种:OLE DB或OleDbConnection (.NET)方式 (使用SQL Server的Microsoft OLE DB提供程序)Provider=sqloledb; Data Sourc ...
- 挖坑:CF712E
#include<cstdio> #include<cstring> #include<algorithm> #define maxn 1000005 using ...
- Scheme-CPS
给出斐波那契数列计算函数,普通版和CPS版 #lang SCHEME (define (fib n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))) ...
- 目标检测中proposal的意义
在目标检测中,从很早就有候选区域的说法,也是在2008年可能就有人使用这个方法,在2014年的卷积神经网络解决目标检测问题的文章中,这个候选框方法大放异彩,先前的目标检测方法主要集中在使用滑动窗口的方 ...
- intellij 出现“Usage of API documented as @since 1.6+”的解决办法
Usage of API documented as @since 1.6+ This inspection finds all usages of methods that have @since ...
- php强制下载文件并显示原始文件名
原来一直没有接触过,这几天一直在玩儿文件上传下载的东西.今天又遇到一个坑. 描述:文件上传至服务器后,如果是rar或则其他的非浏览器直接识别的格式,用户点击链接了后是可以直接就被下载下来的.那么如果上 ...
- Elastarchsearch安装搭建(一)
Elasticsearch是一个实时分布式搜索和分析引擎.一个基于Apache Lucene(TM)的开源搜索引擎.无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进.性能最好的.功能最全 ...
- 各种编码之间的关系以及getBytes的使用
编码基础知识参考http://my.oschina.net/chape/blog/201725 我对此作了简单的概括 iso8859-1 (通常叫做Latin-1) 属于单字节编码,最多能表示的字符范 ...
- Ubuntu 16.04安装和配置Sublime Text 3
1.安装Sublime Text 3 首先添加sublime text 3的仓库: sudo add-apt-repository ppa:webupd8team/sublime-text-3 根据提 ...
- 为 ngui TweenPosition 添加 pingpongone
//---------------------------------------------- // NGUI: Next-Gen UI kit // Copyright © 2011-2015 T ...