leetcode 434.Number of Segments in a String(easy)[分割字符串]
来源:互联网 发布:mongodb 删除数据库 编辑:程序博客网 时间:2024/05/29 15:12
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) { int len = 0; int n = s.length(); if(n == 0) return 0; for(int i=0;i<n;i++) { if(s[i] == ' '&&i-1>=0&&s[i-1] != ' ') ++len; } if(s[n-1] != ' ') ++len; return len; }};
0 0
- leetcode 434.Number of Segments in a String(easy)[分割字符串]
- Leetcode 434. Number of Segments in a String (Easy) (cpp)
- leetcode -- 434. Number of Segments in a String 【字符串处理】
- leetcode 434[easy]---Number of Segments in a String
- 434.Number of Segments in a String(String-Easy)
- LeetCode-Easy部分中标签为String 434. Number of Segments in a String
- 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
- [leetcode]434. Number of Segments in a String
- [leetcode]434. Number of Segments in a String
- LeetCode 434. Number of Segments in a String
- [NOIP2016普及] 买铅笔
- Ngnix 常用命令总结
- 运行java SWT例子
- FragmentTabHost添加Fragment后获取Fragment对象
- [BZOJ1965][Ahoi2005]SHUFFLE 洗牌 数学公式+乘法逆元
- leetcode 434.Number of Segments in a String(easy)[分割字符串]
- SeekBar和RatingBar
- int 类型究竟多少字节?
- 自定义超简单、帅气可滑动删除的ListView
- 项目 1 - 验证算法之(6)堆排序
- Android组件09—悬浮框PopupWindow
- 39. Combination Sum
- Node中的Connect
- EOJ 1028 路由器 floyd