LeetCode-Easy刷题(12) Length of Last Word
来源:互联网 发布:知乎 菠萝斑马 编辑:程序博客网 时间:2024/04/26 18:20
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
查找空格后最后一个单词的长度,如最后一个单词不存在返回0
//基本编码 public static int lengthOfLastWord(String s) { if(s ==null || s.length()<1){ return 0; } int index1 = s.length()-1; while(index1>=0 && s.charAt(index1)==' '){ index1--;//到非空格位置终止 } int index2 = index1; while(index2>=0 && s.charAt(index2)!=' '){ index2--;//到空格位置终止 } return index1 -index2; }
阅读全文
0 0
- LeetCode-Easy刷题(12) Length of Last Word
- [Leetcode 58, easy] Length of Last Word
- 【LeetCode】(58)Length of Last Word(Easy)
- <LeetCode><Easy> 58 Length of Last Word
- leetcode 058 Length of Last Word(难易度:Easy)
- LeetCode-58-Length of Last Word(字符串)-Easy
- Leetcode 58. Length of Last Word (Easy) (cpp)
- 58.leetcode Length of Last Word(easy)[字符串 分割]
- leetcode 58. Length of Last Word(easy)
- Leetcode 刷题:Q58 Length of last word
- LeetCode刷题(C++)——Length of Last Word(Easy)
- LeetCode: Length of Last Word
- LeetCode Length of Last Word
- LeetCode : Length of Last Word
- [Leetcode] Length of Last Word
- [LeetCode] Length of Last Word
- [LeetCode]Length of Last Word
- [leetcode]Length of Last Word
- LeetCode-Easy刷题(11) Maximum Subarray
- Symantec/DigiCer证书认证平台联合升级计划
- SpannableString用法详解
- e的x次方的导数为什么是e^x?lnx的导数为什么是1/x?
- CentOS7.2源码安装Subversion1.9.7【填坑记】
- LeetCode-Easy刷题(12) Length of Last Word
- 纯css svg 改变图片颜色 ios android 小程序
- 视频、音频打时间戳的方法及其音视频同步(播放)原理
- E. Mishka and Divisors Codeforces Round #365 (Div. 2) 01背包
- LeetCode-Easy刷题(13) Plus One
- 深度学习简介
- 算法之河内之塔
- UNity的一些使用
- LeetCode-Easy刷题(14) Add Binary