solution.json 2.0 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
{
  "type": "code_options",
  "author": "https://github.com/begeekmyfriend/leetcode",
  "source": "solution.md",
  "exercise_id": "a32346e4fd59416c86e6fa9fabaa217a",
  "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": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <stdio.h>\n#include <stdlib.h>\nint lengthOfLastWord(char *s)\n{\n\tint len = 0;\n\twhile (*s != '\\0')\n\t{\n\t\tif (s[-1] == ' ' && s[0] != ' ')\n\t\t{\n\t\t\tlen = 1;\n\t\t}\n\t\telse if (*s != ' ')\n\t\t{\n\t\t\tlen++;\n\t\t}\n\t\ts++;\n\t}\n\treturn len;\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 2)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test word\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"%d\\n\", lengthOfLastWord(argv[1]));\n\treturn 0;\n}",
    "language": "cpp"
  },
  "node_id": "dailycode-1f7753ab85df4d1d9a4479becc5c6b4d",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600470793"
}