[leetcode.com]算法题目 - 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.
class Solution {
public:
int lengthOfLastWord(const char *s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int len = strlen(s);
if(==len) return ;
int last = len;
int first = ;
while(last> && s[last-]==' '){
last--;
}
while(first<last && s[first]==' '){
first++;
}
if(==last) return ;
int i;
for(i=last-;i>=first;i--){
if(s[i]==' ') break;
}
return (last-i-);
}
};
我的答案
[leetcode.com]算法题目 - Length of Last Word的更多相关文章
- LeetCode(59)Length of Last Word
题目 Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return th ...
- LeetCode练题——58. Length of Last Word
1.题目 58. Length of Last Word——Easy Given a string s consists of upper/lower-case alphabets and empty ...
- <LeetCode OJ> 58. 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
这是悦乐书的第155次更新,第157篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第14题(顺位题号是58).给定一个字符串,包含戴尔字母.小写字母和空格,返回最后一个单 ...
- [leetcode.com]算法题目 - Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- [leetcode.com]算法题目 - Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- [leetcode.com]算法题目 - Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- [leetcode.com]算法题目 - Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
- [leetcode.com]算法题目 - Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
随机推荐
- vs2008 安装部署 启动项
具体操作办法如下: 鼠标右键安装项目->视图->注册表 依次创建键: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion ...
- 利用PHP脚本辅助MySQL数据库管理4-两个库表结构差异比较
<?php define('DATABASE1', 'coffeetest'); $dbi1 = new DbMysql; $dbi1->dbh = 'mysql://root:mysql ...
- python+selenium—webdriver入门(一)
一.浏览器最大化 二.设置浏览器分辨率大小 三.打印页面title 四.打印URL 五.控制浏览器前进或后退 #!/usr/bin/env python#-*- coding:utf-8 -*- fr ...
- python 部分数据处理代码
# -*- coding:utf8 -*- import os import jieba.posseg as pseg # -*- coding:utf8 -*- import os def spl ...
- Windows 8.1 新控件和功能:
http://msdn.microsoft.com/zh-cn/library/windows/apps/bg182878.aspx#five 将 XAML 树呈现为位图: 适用于 Windows 8 ...
- spring学习 十 schema-based 异常通知,和环绕通知
一 schema-based异常通知 第一步:创建通知类 :新建一个类实现 throwsAdvice 接口,throwsAdvice接口只是标记接口里面并没有任何方法,必须自己写方法,且必须叫 aft ...
- while (~scanf("%d%d",&m,&n))什么用的?
ACM中比较常见,其功能是循环从输入流读取m和n,直到遇到EOF为止,等同于while (scanf("%d%d",&m,&n)!=EOF). scanf()函数返 ...
- JSON转JS对象,JS对象转JSON
一.从服务端发来的json字符串,怎么才能作为JavaScript对象(JSON对象)在web端调用呢? 1.如果使用jQuery,就很方便了,可以在ajax一系列函数中,把参数Datatype传js ...
- 分享url带中文参数,打开html操作完毕跳转jsp页面中文乱码解决
1.在app端分享参数组合时不对传递的url进行任何编码. 2.打开html页面时使用 escape函数对有中文的参数进行编码 escape(GetQueryString("paramete ...
- nginx 下载 大文件被截断
如果出现大文件被截断,且ngix的日志大量出现以下类似报错: 则说明是nginx没有fastcgi_temp的读写权限.其中fastcgi_temp是自己的文件夹名称,每个人的不同且路径也会不同,这个 ...