码迷,mamicode.com
首页 > 其他好文 > 详细

number-of-segments-in-a-string

时间:2016-12-10 18:33:29      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:system   exception   length   com   segment   any   throw   bsp   cep   

https://leetcode.com/problems/number-of-segments-in-a-string/

 

package com.company;


class Solution {
    public int countSegments(String s) {
        String[] strs = s.split(" ");
        int count = 0;
        for (String str : strs) {
            if (str.length() > 0) {
                count++;
            }
        }
        return count;
    }
}

public class Main {

    public static void main(String[] args) throws InterruptedException {

        String s = "Hello, my  name is John";

        Solution solution = new Solution();
        int ret  = solution.countSegments(s);

        // Your Codec object will be instantiated and called as such:
        System.out.printf("ret:%d\n", ret);

        System.out.println();

    }

}

 

number-of-segments-in-a-string

标签:system   exception   length   com   segment   any   throw   bsp   cep   

原文地址:http://www.cnblogs.com/charlesblc/p/6156090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!