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. Android 5.1 - 状态栏充电标志问题

    Android 5.1 Ubuntu14.04  SourceInsigh 电量已满,插着USB头,观察Settings - Battery,电量为100%,状态为full,但仍有充电图标rust 之 ...

  2. 关于childNodes的length的问题

    <ul id="ul1"> <li></li> <li></li> </ul> 这个时候如果 documen ...

  3. Expanding Rods(二分POJ1905)

    Expanding Rods Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13688   Accepted: 3527 D ...

  4. Duilib 鼠标在某控件例如按钮上悬停后,对目标控件操作

    其实对WM_MOUSEHOVER消息的处理,因为WindowImplBase基类中对此消息未处理,所以在自己的窗口类中实现: .h文件中加入 LRESULT OnMouseHover( UINT uM ...

  5. Linux中安装Cisco Packet Tracer

    Cisco Packet tracer是什么? Cisco Packet Tracer是一个强大的网络模拟工具,用于进行Cisco认证时的培训.它为我们 提供了各个路由器和网络设备的良好的接口视图,这 ...

  6. 【leetcode❤python】 112. Path Sum

    #-*- coding: UTF-8 -*-# Definition for a binary tree node.# class TreeNode(object):#     def __init_ ...

  7. vs2012 提示 未能正确加载 "Visual C++ Language Manager Package" 包 的解决办法

    1.点击vs2012菜单栏 工具-> Visual Studio 命令提示 打开命令窗口 2.输入命令 "devenv /Setup" 3.重新打开vs2012

  8. Cheatsheet: 2013 11.12 ~ 11.30

    Mobile Xcode 5 Essentials Android vs. iOS Development: Fight! Using MVC to Understand ASP.NET, iOS, ...

  9. 【转载】Linux的进程间通信-信号量

    原文:Linux的进程间通信-信号量 Linux的进程间通信-信号量 版权声明: 本文章内容在非商业使用前提下可无需授权任意转载.发布. 转载.发布请务必注明作者和其微博.微信公众号地址,以便读者询问 ...

  10. 【转载】.NET程序员走向高端必读书单汇总

    原文:.NET程序员走向高端必读书单汇总 .NET程序员走向高端必读书单汇总 一.知识树 1. 基本能力 1.1 数学 1.2 英语 1.3 语言表达 2. 计算机组织与体系结构 3. 算法与数据结构 ...