【LeetCode】C# 58、Length of Last Word
来源:互联网 发布:软件项目研究成果报告 编辑:程序博客网 时间:2024/06/05 20:12
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.
求最后一个单词的长度。
思路:,利用string.Trim()去掉字符串最左和最右的空格,后从后往前遍历,从第一个字符开始到第一个空格结束。
public class Solution { public int LengthOfLastWord(string s) { s = s.Trim(); int lastIndex = s.LastIndexOf(' ') + 1; return s.Length - lastIndex; }}
阅读全文
0 0
- 【LeetCode】C# 58、Length of Last Word
- [leetcode 58] Length of Last Word
- leetcode-58 Length of Last Word
- Leetcode NO.58 Length of Last Word
- LeetCode #58 length of Last Word
- [LeetCode 58]Length of Last Word
- leetcode || 58、Length of Last Word
- LeetCode 58 Length of Last Word
- [Leetcode 58, easy] Length of Last Word
- Length of Last Word (leetCode 58)
- leetcode[58]:Length of Last Word
- 【leetcode c++】58 Length of Last Word
- leetcode 58:Length of Last Word
- LeetCode---(58)Length of Last Word
- leetcode-58-Length of Last Word
- Leetcode# 58 Length of Last Word
- [leetcode-58]Length of Last Word(c)
- leetcode 58: Length of Last Word
- charles之配置
- HDU 5168 Legal path 最短路 OR DP
- Git 常用整理
- python-web.py 开发入门
- 集群管理——(2)关于登录重新回到图形登录界面的错误和硬盘引导错误的解决方法!
- 【LeetCode】C# 58、Length of Last Word
- C# 生成8位灰度图bmp
- 在excel2003中,用A表示第一列,B表示第二列....Z表示第26列,AA表示27列,AB表示28列。
- 网址
- Eclipse快捷键
- jQuery $.each用法
- $.extend()方法扩展
- UVa10779
- 用JS获取地址栏参数的方法