434. Number of Segments in a String
来源:互联网 发布:淘宝实体娃娃是真的吗 编辑:程序博客网 时间:2024/06/05 17:00
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
public class Solution { public int countSegments(String s) { if(s.length()==0||s.trim().isEmpty()) return 0; String str=s.trim(); int j=0; for(int i=0;i<str.length();i++){ if(str.charAt(i)-'A'==-33&&str.charAt(i+1)-'A'!=-33) j++; } if(j==0) return 1; else return j+1; }}
阅读全文
0 0
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String*
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434.Number of Segments in a String(String-Easy)
- String:434. Number of Segments in a String
- Leetcode434. Number of Segments in a String
- Python实现设计模式--05.建造者模式(Builder Pattern)
- Rhel7.2Mysql数据库安装及配置
- 刷吉米多维奇系列小结(一)
- 【POJ1287】Networking(最小生成树)
- linux总结 三
- 434. Number of Segments in a String
- 2017年8月3日- 星期四
- 二叉排序树(Binary Sort Tree)的查找递归算法
- DOM拷贝clone()
- js高级程序设计(第三版)第二章
- spark-2.2.0源码阅读环境的搭建
- SpringMVC4.3x教程之五SpringMVC表单标签的使用
- Linux系统中的临时文件
- 深入解析Spring架构与设计原理-AOP