LeetCode_58. Length of Last Word
58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' '
, return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is defined as a character sequence consists of non-space characters only.
Example:
Input: "Hello World"
Output: 5
package leetcode.easy; public class LengthOfLastWord {
@org.junit.Test
public void test() {
System.out.println(lengthOfLastWord("Hello World"));
} public int lengthOfLastWord(String s) {
String str = s.trim();
String[] buff = str.split(" ");
return buff[buff.length - 1].length();
}
}
LeetCode_58. Length of Last Word的更多相关文章
- [LeetCode] Length of Last Word 求末尾单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 【leetcode】Length of Last Word
题目简述 Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return ...
- [LeetCode] Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- [LintCode] Length of Last Word 求末尾单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- Java for LeetCode 058 Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- LeetCode 58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 【Length of Last Word】cpp
题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t ...
- 【LeetCode】58 - Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- Leetcode: Length of Last Word in python
Length of Last Word Total Accepted: 47690 Total Submissions: 168587 Given a string s consists of ...
随机推荐
- centos安装nodejs和配置npm
1.下载安装nodejs 1 wget http://nodejs.org/dist/v7.4.0/node-v7.4.0.tar.gz 2 yum install gcc openssl-devel ...
- H3C常见视图及命令
H3C常见视图及命令 H3C Comware的视图模式 1.用户视图:查看系统的硬件和系统的信息 2.系统视图(类似于Cisco的配置模式) 3.路由协议视图 4.接口视图 5.用户界面视图 各种视图 ...
- Mac卸载Python
推荐使用 Homebrew 来安装第三方工具 自己安装的python散落在电脑各处,删除起来比较麻烦 今天在此记录一下删除的过程(以Python3.6为例) 删除Python 3.6 framewor ...
- KM 最大权匹配 UVA 1411/POJ 3565
#include <bits/stdc++.h> using namespace std; inline void read(int &num) { char ch; num = ...
- 54、servlet3.0-ServletContainerInitializer
54.servlet3.0-ServletContainerInitializer Shared libraries(共享库) / runtimes pluggability(运行时插件能力) 1.S ...
- 洛谷 P3374 【模板】树状数组 1 & P3368 【模板】树状数组 2 题解
一维树状数组的作用主要是单点修改,单点查询,区间修改,区间查询. 模板1是单点修改,区间查询:模板2是单点查询,区间修改. 模板1: #include<iostream> #include ...
- 十五.DNS子域授权、分离解析、缓存DNS服务器
1.搭建基本DNS服务器 pc7: 1.1 安装软件包 ]# yum -y install bind-chroot bind bind //域名服务包 bind-chroot //提 ...
- /etc/sysconfig/network-scripts/ifcfg-ensxx
TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static # 获取ip的方式,static表示静态设置的ip,还有dhcp,系统 ...
- LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿
二次联通门 : LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿 /* LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿 dp 记录一下前驱 ...
- 爬虫(十四):scrapy下载中间件
下载器中间件是介于Scrapy的request/response处理的钩子框架,是用于全局修改Scrapy request和response的一个轻量.底层的系统. 激活Downloader Midd ...