leetcode 58. Length of Last Word(easy)
来源:互联网 发布:西蒙斯数据 编辑:程序博客网 时间:2024/04/26 01:57
注意最后一个单词后边可能会有若干个空格的情况。
这些简单题就是要注意特殊情况的处理。
public class Solution {public int lengthOfLastWord(String s) { int len = s.length(); int count = 0; int i; int flag = 0; for(i=len-1;i>=0;i--) { if(flag == 0 && s.charAt(i) == ' ') continue; if(flag == 0 && s.charAt(i) != ' ') flag = 1; if(flag == 1 && s.charAt(i) == ' ') break; count++; } return count; }public static void main(String args[]){String s = "hello world ";System.out.println(new Solution().lengthOfLastWord(s));}}
0 0
- leetcode 58. Length of Last Word(easy)
- [Leetcode 58, easy] Length of Last Word
- 【LeetCode】(58)Length of Last Word(Easy)
- <LeetCode><Easy> 58 Length of Last Word
- Leetcode 58. Length of Last Word (Easy) (cpp)
- 58.leetcode Length of Last Word(easy)[字符串 分割]
- leetcode 058 Length of Last Word(难易度:Easy)
- 58. Length of Last Word [easy] (Python)
- Length of Last Word(easy)
- LeetCode-58-Length of Last Word(字符串)-Easy
- LeetCode-Easy刷题(12) Length of Last Word
- 58. Length of Last Word Leetcode Python
- [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
- <LeetCode OJ> 58. Length of Last Word
- 鼠标选择的内容会被自动删除
- linux centos中搭建lnmp环境
- HeadFirst设计模式 (设计原则) 第一天
- Swift之SDWebImage第三方框架
- TRFC/QRFC
- leetcode 58. Length of Last Word(easy)
- 人工神经网络基本原理
- Mybatis Generator最完整配置详解
- javascript之继承详解(一)
- android 半透明图层用户引导、用户指导、用户教导,教用户怎么使用app的页面制作
- stop和suspend 不推荐使用的原因
- kickstart自动安装光盘
- WKWebView加载进度条(仿微信)
- 最新ViewPagerIndicator的使用