【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 ...
随机推荐
- ios 状态码
9001 无网络 9002 url错误 9003 链接超时 9005 json解析错误 9503 503 error
- 64位Java开发平台的选择,如何区分JDK,Tomcat,eclipse的32位与64版本
当你想下载Linux.JDK.Tomcat.eclipse时,你是下载32位版本还是64位版本?64位版本有两种,应该选哪一个? 当你看到这些内容:x86.x64.x86-32.x86-64.ia64 ...
- JVM调优实战
JVM调优实战 文档修订记录 版本 日期 撰写人 审核人 批准人 变更摘要 & 修订位置 ...
- Chapter 2 Open Book——34
His gaze became appraising. "You put on a good show," he said slowly. 他的凝视变成了评价.“你上演了一场好戏” ...
- C++类的实例化的两种方法
C++ 类的实例化有两种方法: 直接定义对象: 先定义一个类: class A { public: A(); virtual ~A(); ... ... }; 类实现略. 用的时候: A a; ...
- 接口速度慢问题查找(TTFB时间长)
前些天自己写了一个网站,但是发现接口的速度按超级慢,业务逻辑并不复杂,原因究竟在哪呢? 首先说一下,我的数据库和项目均在同一台服务器上,按道理来说,接口访问本地的数据库应该会很快才对. 后来我发现线上 ...
- 每天点滴的进行,css+div简单布局...布局
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- PHP字符串转义
与PHP字符串转义相关的配置和函数如下: 1.magic_quotes_runtime 2.magic_quotes_gpc 3.addslashes()和stripslashes() 4.mysql ...
- wpf为ListBox添加渐变
<Style.Triggers> <Trigger Property="ListBox.AlternationIndex" Value="1" ...
- Process Explorer(增强任务管理器) V16.05 免费绿色版
软件名称: Process Explorer(增强任务管理器)软件语言: 中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 1.2MB图片预 ...