【Leetcode 434. Number of Segments in a String】
来源:互联网 发布:聊天机器人对话数据库 编辑:程序博客网 时间:2024/05/17 11:37
434. Number of Segments in a String
Total Accepted: 3749Total Submissions: 9646Difficulty: EasyContributors: love_FDU_llp
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.
Please note that the string does not contain any non-printable characters.
Example:
Input: “Hello, my name is John”
Output: 5
java解决方法:
package Test;public class NumberSegments { public static void main(String[] args) { // TODO Auto-generated method stub NumberSegments test=new NumberSegments(); test.countSegments(", , , , a, eaefa"); } public int countSegments(String s) { if("".equals(s)){ return 0; } int count=0; String [] aStrings=s.split(" "); for(int i=0;i<aStrings.length;i++){ if(!"".equals(aStrings[i])){ count++; } } System.out.println(count); return count; }}
0 0
- Leetcode Number of Segments in a String
- LEETCODE--Number of Segments in a String
- LeetCode 434. Number of Segments in a String
- LeetCode 434. Number of Segments in a String
- 【Leetcode 434. Number of Segments in a String】
- leetcode 434. Number of Segments in a String
- LeetCode 434. Number of Segments in a String
- LeetCode 434. Number of Segments in a String
- Leetcode 434. Number of Segments in a String (Easy) (cpp)
- 【LeetCode】 434. Number of Segments in a String
- [leetcode]434. Number of Segments in a String
- [leetcode]434. Number of Segments in a String
- LeetCode 434. Number of Segments in a String
- Leetcode 434. Number of Segments in a String
- Leetcode-434. Number of Segments in a String
- LeetCode-434. Number of Segments in a String
- [LeetCode]434. Number of Segments in a String
- 【Leetcode】434. Number of Segments in a String
- 第16周项目1 验证算法(8)基数排序
- Curl移植笔记
- 【SSH网上商城】--SSH简介
- 求递增序列中和为S的乘积最小的两个数
- 第十六周项目1-验证算法-堆排序
- 【Leetcode 434. Number of Segments in a String】
- 移动端学习
- 发布java项目或者web项目修改工程名字的问题
- yolo v2微调
- 第十六周--项目一(3)
- 前端开发必须知道的JS(一) 原型和继承
- ios cookie同步和管理偶尔失效问题
- 【第16周 项目4 - 英文单词的基数】
- MAC pro git 使用攻略