首页 > 其他分享 >Length of Last Word

Length of Last Word

时间:2023-06-14 10:57:36浏览次数:47  
标签:Last last word Explanation length Length words Input Word

Given a string s consisting of words and spaces, return the length of the last word in the string.

A word is a maximal substring consisting of non-space characters only.

Example 1:

Input: s = "Hello World"
Output: 5
Explanation: The last word is "World" with length 5.

Example 2:

Input: s = "   fly me   to   the moon  "
Output: 4
Explanation: The last word is "moon" with length 4.

Example 3:

Input: s = "luffy is still joyboy"
Output: 6
Explanation: The last word is "joyboy" with length 6.

Solution:

class Solution(object):
    def lengthOfLastWord(self, s):
        words = s.split()  
        return len(words[-1]) if words else 0

标签:Last,last,word,Explanation,length,Length,words,Input,Word
From: https://www.cnblogs.com/artwalker/p/17479566.html

相关文章

  • 2023全国卷甲卷理科数学Word解析版
    前言真题图片相关下载2023年高考全国甲卷理科数学真题版+解析版,提取码请微信联系:wh1979448597.......
  • 2023全国卷乙卷理科数学Word解析版
    前言真题图片相关下载高考真题版本(Word+PDF)2023年高考全国乙卷数学(理)真题解析版,提取码请微信联系:wh1979448597.......
  • 浏览器缓存内幕与getLastModified方法
    源:评:[问题描述:] 1)userlogout之后,按回退按钮又可进行提交; IE缓存的问题。 登出系统之后,输入刚才的URL,依然能访问原来的页面(但是有任何操作就会返回到登陆的页面),这是IE缓存的问题,只要清除调IE的缓存就好。   清除IE缓存的方法有两种,一是在浏览器端控制,二是在服务器端返回Re......
  • docker-compose搭建wordpress
    前言我们都知道,docker是一个运行容器的软件。同时它也配置了一个运行一组容器的软件,叫做docker-compose。当我们使用非常小规模容器化应用的时候,我们可以使用此docker-compose去做。 docker-compose的介绍根据官网的描述,docker-compose是一个能够管理多容器的工具,可以使用yam......
  • Elasticsearch自签证书
    ****如果方式适合安装时没有配置及证书相关配置,而安装后进行的证书自签一、自签证书1、进入工作目录进入容器,bin目录下有生成证书的脚本,路径下文件展示如下(我这里是以docker容器部署的模式演示的)[root@363474ada611elasticsearch]#llbin/total19604-rwxr-xr-x.1......
  • Elasticsearch8 单机以及集群部署(docker-compose)
    本文以Elasticsearch8.8.0为例,介绍一下单机安装ES,使用docker-compose方式进行便捷管理需要准本docker环境:一键安装脚本 https://www.cnblogs.com/Alay/p/15433473.html需要准备docker-compose环境:一键安装脚本 https://www.cnblogs.com/Alay/p/15433907.html官网阅......
  • word跨文件批量替换
    开发工具->vbs编辑新建一个模块SubWord内容替换()Dim筛选AsFileDialogDim文件名,文件AsDocumentDimpd,计数AsIntegerSet筛选器=Application.FileDialog(msoFileDialogFilePicker)With筛选器.Al......
  • springcloud 启动失败 YAMLException java.nio.charset.MalformedInputException Inp
     上面这个是错误信息,但是该微服务在本地启动的时候是可以的,但是本地打成jar包本地执行的时候就失败。需要再Java-jar的中间加一下字符编码java-Dfile.encoding=utf-8-jar  myself.jar   myself.jar是自己的jar包问题解决......
  • 对比 redis cluster 和 elasticsearch
    一.对比redis提供了redissentinal的高可用策略,以及rediscluster来支持扩展性(同时也支持高可用)。rediscluster,ealsticsearch都属于有状态数据存储服务,这里做一个简单的对比。特性redisclusterelasticsearch 备注主要设计目标在保证highperformance的条件下,提......
  • flume+elasticsearch
    简单描述一下这个例子:将项目日志实时采集到elasticsearch,便于统一管理。1.收集日志格式为:log4j.properties: org.apache.log4j.Logger: %d{ISO8601}[%l-%M]-[%p]%t%m%nlogback.xml:org.slf4j.Logger:  %date[%logger:%L]-[%level]%thread%msg%n2.flume1.7.0(flume......