{
  "type": "code_options",
  "author": "https://github.com/qiyuangong/leetcode",
  "source": "solution.md",
  "exercise_id": "5bac8a7cc669449f8c4f98f86335f84e",
  "keywords": "字符串",
  "title": "最后一个单词的长度",
  "desc": [
    {
      "content": "\n<p>给你一个字符串 <code>s</code>，由若干单词组成，单词之间用空格隔开。返回字符串中最后一个单词的长度。如果不存在最后一个单词，请返回 0 。</p><p><strong>单词</strong> 是指仅由字母组成、不包含任何空格字符的最大子字符串。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>s = \"Hello World\"<strong><br />输出：</strong>5</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>s = \" \"<strong><br />输出：</strong>0</pre><p> </p><p><strong>提示：</strong></p><ul>\t<li><code>1 <= s.length <= 10<sup>4</sup></code></li>\t<li><code>s</code> 仅有英文字母和空格 <code>' '</code> 组成</li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "class Solution(object):\n\tdef lengthOfLastWord(self, s):\n\t\t\"\"\"\n\t\t:type s: str\n\t\t:rtype: int\n\t\t\"\"\"\n\t\tif len(s) == 0:\n\t\t\treturn 0\n\t\ttemp = s.split(' ')\n\t\ttemp = [t for t in temp if len(t) > 0]\n\t\tif len(temp) == 0:\n\t\t\treturn 0\n\t\telse:\n\t\t\treturn len(temp[-1])\n# %%\ns = Solution()\nprint(s.lengthOfLastWord(s = \"Hello World\"))",
    "language": "python"
  },
  "node_id": "dailycode-4047f84489c9453eb082e3e15cf6ad39",
  "license": "csdn.net",
  "created_at": 1637894161,
  "topic_link": "https://bbs.csdn.net/topics/600470793"
}