每天一道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.

For example,

Input: "Hello, my name is John"

Output: 5

    public int countSegments(String s) {
String trimmed = s.trim();
if (trimmed.length() == 0)
return 0;
else
return trimmed.split("\\s+").length;
}
上一篇:解决在CentOS6.5下安装OpenStack(Icehouse版本 )出现的glance服务无法正常工作的问题


下一篇:在Sublime Text 3 中安装SublimeLinter,Node.js进行JS&CSS代码校验