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 = ;
for (String str : strs) {
if (str.length() > ) {
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的更多相关文章

  1. [LeetCode] 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 ...

  2. Leetcode: 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 ...

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

  4. 【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 ...

  5. [Swift]LeetCode434. 字符串中的单词数 | 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 ...

  6. 434. Number of Segments in a String

    原题: 434. Number of Segments in a String 解题: 刚看到题目时,觉得可以通过统计空格个数,但想想有可能会有多个空格的情况 思路: 一:遍历字符,if条件碰到非空格 ...

  7. 434. Number of Segments in a String 字符串中的单词个数

    [抄题]: Count the number of segments in a string, where a segment is defined to be a contiguous sequen ...

  8. LeetCode_434. Number of Segments in a String

    434. Number of Segments in a String Easy Count the number of segments in a string, where a segment i ...

  9. [LC] 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 ...

  10. C#LeetCode刷题之#434-字符串中的单词数​​​​​​​(Number of Segments in a String)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3941 访问. 统计字符串中的单词个数,这里的单词指的是连续的不是 ...

随机推荐

  1. YTU 2987: 调整表中元素顺序(线性表)

    2987: 调整表中元素顺序(线性表) 时间限制: 1 Sec  内存限制: 2 MB 提交: 1  解决: 1 题目描述 若一个线性表L采用顺序存储结构存储,其中所有元素都为整数.设计一个算法,将所 ...

  2. css select 样式列表-----另一种样式列表

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org ...

  3. C#委托之泛型

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  4. Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏

    Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ ...

  5. linux脚本随笔-01

    #### 获取配置文件配置路径,javapath为配置项,var为具体的配置值 eval $(awk -F "javapath=" '{if($2=="") { ...

  6. Winform自定义分页控件的实现

    实现效果 有点丑陋 但是功能是没问题的 测试过 实现思路 先创建一个用户控件 代码实现 public partial class PagerControl : UserControl { ; /// ...

  7. python代码

    f=open('/home/xbwang/newtextsimilarity/data/glove/glove.840B.300d.txt','r') count = 0 print ' '.join ...

  8. hdu 2053 Switch Game 水题一枚,鉴定完毕

    Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. 列出本机JCE提供者,支持消息摘要算法,支持公钥私钥算法

    import java.security.Provider; import java.security.Security; public class TestBouncyCastle { public ...

  10. Jquery实现图片上下一张

    注:调试的时候发现ff下有兼容性问题,把jquery换成4.4版本就没问题了,问题应该在e.offseX上ff不支持此属性,以图片中间宽度为界限,鼠标移动在左边点击跳转到一个链接,鼠标移动右边点击跳转 ...