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 = ;
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的更多相关文章
- [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 ...
- 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 ...
- 每天一道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 ...
- 【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 ...
- [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 ...
- 434. Number of Segments in a String
原题: 434. Number of Segments in a String 解题: 刚看到题目时,觉得可以通过统计空格个数,但想想有可能会有多个空格的情况 思路: 一:遍历字符,if条件碰到非空格 ...
- 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 ...
- 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 ...
- [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 ...
- C#LeetCode刷题之#434-字符串中的单词数(Number of Segments in a String)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3941 访问. 统计字符串中的单词个数,这里的单词指的是连续的不是 ...
随机推荐
- 自己封装的OKhttp请求
package com.create.qdocumentimtest.rxjavatest; import com.squareup.okhttp.Callback; import com.squar ...
- 各种drawable
BitmapDrawable 可以把小图片平铺布满布局来设置背景. PictureDrawable 记录绘制过程 ClipDrawable 裁剪 进度条 InsetDrawabl ...
- Cocos2dx-lua开发之c++绑定到lua
一. 简单介绍 文章介绍是在实际的游戏开发项目中,将自定义的C++类绑定到lua中,能够让lua调用c++类.会创建一个python脚本,执行python脚本会让自动将我们的c++类绑定到lua.生成 ...
- YTU 2344: 先序遍历二叉树
原文链接:https://www.dreamwings.cn/ytu2344/2603.html 2344: 先序遍历二叉树 时间限制: 1 Sec 内存限制: 128 MB 提交: 4 解决: ...
- StringBuild,StringFormat," "+" " 三种方法速度测试
测试方式: Stopwatch sw = new Stopwatch(); sw.Start(); string tmp = ""; StringBuilder sb = new ...
- 深入理解include预编译原理
http://ticktick.blog.51cto.com/823160/596179 你了解 #include 某个 .h 文件后,编译器做了哪些操作么? 你清楚为什么在 .h文件中定义函数实现的 ...
- 2016年10月14日 星期五 --出埃及记 Exodus 18:25
2016年10月14日 星期五 --出埃及记 Exodus 18:25 He chose capable men from all Israel and made them leaders of th ...
- Linux内核中的Kconfig、xx.defconfig、xx.config、Makefile
什么是Kconfig.xx.defconfig.xx.config.Makefile Kconfig: 一个文本形式的文件,其中主要作用是在内核配置时候,作为配置选项. xx.deconfig: Li ...
- 【SQL】SQL中笛卡尔积、内连接、外连接的数据演示
SQL的查询语句中,常使用到内连接.外连接,以及连接的基础--笛卡尔积运算. 在简单的SQL中,也许我们还分辨清楚数据如何连接,一旦查询复杂了,脑子也犯浆糊了,迷迷糊糊的. 本文,简单以数据形式记录连 ...
- 获取指定的系统路径 SHGetSpecialFolderPath
1.获取桌面的系统路径 TCHAR szLink[MAX_PATH + ] = { }; SHGetSpecialFolderPath(,szLink,CSIDL_DESKTOPDIRECTORY,) ...