LeetCode——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.
For example,
Given s = "Hello World"
,
return 5
.
中文:给定一个字符串,包括大写/小写字母和空格字符,返回字符串中最后一个单词的长度。
假设最后一个单词不存在,返回0.
注意:一个单词被定义为仅包括非空字符的字符序列。
比如:
给定 s="Hello World",
返回 5.
此题可能是leetcode上面的最简单的一道题了。
Java:
public int lengthOfLastWord(String s) {
if(s.trim().equals(""))
return 0;
String[] str = s.split("\\s+");
int len = str.length;
return str[len-1].length();
}
LeetCode——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 @ Python
原题地址:https://oj.leetcode.com/problems/length-of-last-word/ 题意: Given a string s consists of upper/lo ...
- [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 in python
Length of Last Word Total Accepted: 47690 Total Submissions: 168587 Given a string s consists of ...
- [Leetcode] Length of last word 最后一个单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters' ', return the le ...
- [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 最后一个字的长度
class Solution { public: int lengthOfLastWord(const char *s) { ; string snew=s; ,len=strlen(s); ]; ) ...
- leetcode 题解: Length of Last Word
leetcode: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', re ...
- 【一天一道LeetCode】#58. Length of Last Word
一天一道LeetCode系列 (一)题目 Given a string s consists of upper/lower-case alphabets and empty space charact ...
随机推荐
- Migration data on SQL
从表里面导出数据XML: -- export declare @xml xml set @xml = (select * from ( select TableName = 'Schema', xml ...
- iOS 设置状态栏的颜色
1.在plist文件中设置如下属性: 2.在delegate中设置 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarSt ...
- 一个页面从输入URL到页面加载显示完成的详细过程
下面以访问baidu页面来做一个过程分析 输入 URL:http://www.baidu.com DNS 域名解析 计算机无法识别域名,计算机与计算机之间要想进行通信,必须通过ip地址用来定位该计算机 ...
- C/C++ 结构体成员在内存中的对齐规则
这几天在看王艳平的<windows 程序设计>,第5章讲解了MFC框架是怎么管理窗口句柄到窗口实例之间的映射,用到了两个类CPlex和CMapPtrToPtr,用于管理内存分配的类(避免因 ...
- 嵌入式linux的网络编程(1)--TCP/IP协议概述
嵌入式linux的网络编程(1)--TCP/IP协议概述 1.OSI参考模型及TCP/IP参考模型 通信协议用于协调不同网络设备之间的信息交换,它们建立了设备之间互相识别的信息机制.大家一定都听说过著 ...
- Android 开发笔记 “android调试遇到ADB server didn't ACK以及顽固的sjk_daemon进程 ”
资源来源:http://blog.csdn.net/wangdong20/article/details/20839533 做Android调试的时候经常会遇到,程序写好了,准备接上手机调试,可不一会 ...
- C#_C++_SDK_WM_KEYDOWN人物卡顿延迟解决方法
提问者采纳 由Keydown和keyup事件组合,keyDown来判定按下,此时开始移动,KeyUp判定松开,这样可行否? 追问 这是我一开始的写法,但就是因为 键盘重复延迟 导致keydown后会有 ...
- multi-threaded copy command - robocopy
we can copy files by the powerful robocopy tool, and it allow copy using muliti-threaded as well. As ...
- centos7 install magento
http://mirrors.yun-idc.com/epel/7/x86_64/e/epel-release-7-2.noarch.rpmrpm --import /etc/pki/rpm-gpg/ ...
- Sublime 配置&插件推荐
sublime 配置&插件推荐 Sublime编辑器的新鲜特性同时选中多个 先选中一个 再Command + D Command + P @搜索函数 #搜索关键字迷你地图 安装package ...