[leetcode]Length of Last Word
简单题。
public class Solution {public int lengthOfLastWord(String s) {// Start typing your Java solution below// DO NOT write main() functionint len = s.length();if (len == 0) return 0;boolean meetWord = false;int count = 0;for (int i = len-1; i >= 0; i--) {char c = s.charAt(i);if (isSpace(c) && !meetWord) continue;if (isSpace(c) && meetWord) break;meetWord = true;count++;}return count;}private boolean isSpace(char c) {return c == ' ';}
}
转载于:https://www.cnblogs.com/lautsie/p/3254107.html
[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 ...
- 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(最后一个单词的长度)
题意:给出一个字符串,其中包含大小写字母,空格,求其最后一个单词的长度 思路:将字符串以空格为分隔符,将其分割成字符串数组 代码如下: public class Solution {public in ...
- LeetCode刷题记录9——58. Length of Last Word(easy)
LeetCode刷题记录9--58. Length of Last Word(easy) 目录 LeetCode刷题记录9--58. Length of Last Word(easy) 题目 语言 思 ...
- leetcode python3 简单题58. Length of Last Word
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第五十八题 (1)题目 英文: Given a string s consists ...
- LeetCode: 58. Length of Last Word
051101 题目 Given a string s consists of upper/lower-case alphabets and empty space characters ' ', re ...
- leetcode 58. Length of Last Word 题解【C++/Java/Python/JS】
58. 最后一个单词的长度 58. Length of Last Word 题目: 给定一个仅包含大小写字母和空格' ' 的字符串,返回其最后一个单词的长度. 如果不存在最后一个单词,请返回0 . 说 ...
- 【LeetCode从零单排】No58.Length of Last Word
题目 Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return th ...
- C#LeetCode刷题之#58-最后一个单词的长度(Length of Last Word)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3927 访问. 给定一个仅包含大小写字母和空格 ' ' 的字符串, ...
- LeetCode 58. Length of Last Word
58. Length of Last Word My Submissions QuestionEditorial Solution Total Accepted: 90032 Total Submis ...
最新文章
- MLIR Python绑定
- 对频率论(Frequentist)方法和贝叶斯方法(Bayesian Methods)的一个总结
- 【模型调优】风控模型调优相关知识
- mysql2005错误_sql-server-2005 – SQL Server 2005错误701 – 内存不足
- Java assertion 介绍和用法
- web安全漏洞加固方案简析
- 20180316 数组所占空间
- 如何在Chrome调试器里检查嵌套Observable对象
- c#和WIN32 调用
- div css入门教程,更简洁CSS清理浮动方式:clearfix
- Spring Boot 文件上传功能实现与简单示例
- 学习可以借鉴的大牛们的网站
- VC中,如何将十六进制字符串转换为十进制数?
- 数值分析 解线性方程组的编程实现(Hilbert)
- Python 新手入门必学十大模块之一:sys 和 os
- C# Winform 实现窗体无系统边框,但是具有系统边框的所有功能,同时保证控件不闪烁
- 简单的记账方法有哪些?
- 宝贝怎么查询历史价格?有何意义?
- 跳槽没有20%以上的加薪就等于降薪?我:跳槽还降薪~
- 解决 Xshell6强制升级
热门文章
- flink知识点总结
- C语言_函数指针高级用法
- 6月28日云栖精选夜读丨优酷世界杯的好后卫:云计算成为靠谱的流媒体保障体系...
- 【智能家居篇】wifi网络结构(下)
- 记TensorFlow项目开源一周年
- sql语法:inner join on, left join on, right join on具体用法
- FtpWebRequest(转)---关于C/S中文件的上传,下载,获得文件列表
- pyqt5-两个窗口之间相互显示隐藏
- STM32CubeMX官网下载方法
- 黑马程序员_java基础笔记(03)...面向对象