LeetCode 434. Number of Segments in a String
来源:互联网 发布:c语言文件指针换行 编辑:程序博客网 时间:2024/05/17 13:39
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
简单题,从头到尾遍历一遍找到单词块就行了。
最近一直在准备期末考试,无心刷题,这样不行啊,不能找借口偷懒了,要坚持
class Solution {public: int countSegments(string s) { if(!s.size()) return 0; bool start = false; int count =0; int i; char tmp; for(i = 0; i < s.size(); i ++){ if(s[i] == ' '){ if(start){ start = false; count ++; } }else{ start = true; } } if(start) count ++; return count; }};
0 0
- Leetcode Number of Segments in a String
- LEETCODE--Number of Segments in a String
- LeetCode 434. Number of Segments in a String
- LeetCode 434. Number of Segments in a String
- 【Leetcode 434. Number of Segments in a String】
- leetcode 434. Number of Segments in a String
- LeetCode 434. Number of Segments in a String
- LeetCode 434. Number of Segments in a String
- Leetcode 434. Number of Segments in a String (Easy) (cpp)
- 【LeetCode】 434. Number of Segments in a String
- [leetcode]434. Number of Segments in a String
- [leetcode]434. Number of Segments in a String
- LeetCode 434. Number of Segments in a String
- Leetcode 434. Number of Segments in a String
- Leetcode-434. Number of Segments in a String
- LeetCode-434. Number of Segments in a String
- [LeetCode]434. Number of Segments in a String
- 【Leetcode】434. Number of Segments in a String
- Atitit 软件开发中 瓦哈比派的核心含义以及修行方法以及对我们生活与工作中的指导意义
- 剑指offer——面试题49:不使用atoi库函数实现把字符串转换成整数
- Java程序员从笨鸟到菜鸟之(三十)javascript弹出框、事件、对象化编程
- JavaScript中的this用法
- 什么是设计模式
- LeetCode 434. Number of Segments in a String
- 文件锁
- 常用js自定义函数
- 单词的长度
- IO
- qt designer启动后不显示界面问题的原因与解决办法
- Java程序员从笨鸟到菜鸟之(二十九)javascript对象的创建和继承实现
- SQL语句获取日期的月份
- 基于php的表单提交发送邮件系统