number-of-segments-in-a-string
Posted 笨鸟居士的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了number-of-segments-in-a-string相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章