首页 > 其他 > 详细

每天一道LeetCode--434. Number of Segments in a String

时间:2016-12-05 23:29:26      阅读:257      评论:0      收藏:0      [点我收藏+]

 

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;
    }

 

每天一道LeetCode--434. Number of Segments in a String

原文:http://www.cnblogs.com/xiaoduc-org/p/6135563.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!