{"id":2456,"date":"2023-10-13T15:55:14","date_gmt":"2023-10-13T07:55:14","guid":{"rendered":"https:\/\/white-night.club\/?p=2456"},"modified":"2023-11-09T11:07:50","modified_gmt":"2023-11-09T03:07:50","slug":"ad46","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/13\/ad46\/","title":{"rendered":"58.\u00a0\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0<code>s<\/code>\uff0c\u7531\u82e5\u5e72\u5355\u8bcd\u7ec4\u6210\uff0c\u5355\u8bcd\u524d\u540e\u7528\u4e00\u4e9b\u7a7a\u683c\u5b57\u7b26\u9694\u5f00\u3002\u8fd4\u56de\u5b57\u7b26\u4e32\u4e2d\u00a0<strong>\u6700\u540e\u4e00\u4e2a<\/strong>\u00a0\u5355\u8bcd\u7684\u957f\u5ea6\u3002<\/p>\n\n\n\n<p><strong>\u5355\u8bcd<\/strong>&nbsp;\u662f\u6307\u4ec5\u7531\u5b57\u6bcd\u7ec4\u6210\u3001\u4e0d\u5305\u542b\u4efb\u4f55\u7a7a\u683c\u5b57\u7b26\u7684\u6700\u5927\u5b50\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = \"Hello World\"\n<strong>\u8f93\u51fa\uff1a<\/strong>5\n<strong>\u89e3\u91ca\uff1a<\/strong>\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u662f\u201cWorld\u201d\uff0c\u957f\u5ea6\u4e3a5\u3002\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = \"   fly me   to   the moon  \"\n<strong>\u8f93\u51fa\uff1a<\/strong>4<strong>\n\u89e3\u91ca\uff1a<\/strong>\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u662f\u201cmoon\u201d\uff0c\u957f\u5ea6\u4e3a4\u3002\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = \"luffy is still joyboy\"\n<strong>\u8f93\u51fa\uff1a<\/strong>6\n<strong>\u89e3\u91ca\uff1a<\/strong>\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u662f\u957f\u5ea6\u4e3a6\u7684\u201cjoyboy\u201d\u3002\n<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li><code>1 &lt;= s.length &lt;= 10<sup>4<\/sup><\/code><\/li>\n\n\n\n<li><code>s<\/code>&nbsp;\u4ec5\u6709\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c&nbsp;<code>' '<\/code>&nbsp;\u7ec4\u6210<\/li>\n\n\n\n<li><code>s<\/code>&nbsp;\u4e2d\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u5355\u8bcd<\/li>\n<\/ul>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>\u8111\u7b4b\u6025\u8f6c\u5f2f<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u4e3a\u4ec0\u4e48\u8bf4\u662f\u8111\u7b4b\u6025\u8f6c\u5f2f\u5462\uff1f\u6211\u4e00\u5f00\u59cb\u60f3\u7684\u662f\uff1a\u76f4\u63a5\u4ece\u5934\u5f00\u59cb\u904d\u5386\u5457\uff0c\u7136\u540e\u5224\u65ad\u662f\u4e0d\u662f\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\uff0c\u5b8c\u4e8b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\r\npublic:\r\n    int lengthOfLastWord(string s) {\r\n        int len=s.length();\r\n        int wordLen=0,flag=false;\r\n        for(int i=0;i&lt;len;i++)\r\n        {\r\n            if(s&#91;i]==' ')\r\n            {\r\n                flag=true;\r\n            }else\r\n            {\r\n                if(flag==true)\r\n                {\r\n                    wordLen=1;\r\n                    flag=false;\r\n                }else\r\n                {\r\n                    wordLen++;\r\n                }\r\n            }\r\n        }\r\n        return wordLen;\r\n    }\r\n};<\/code><\/pre>\n\n\n\n<p>\u8bf4\u5b9e\u8bdd\u6709\u70b9\u66b4\u529b\u4e86\u3002\u60f3\u770b\u770b\u6709\u6ca1\u6709\u5176\u4ed6\u65b9\u6cd5\uff0c\u7ed3\u679c\u53d1\u73b0\u76f4\u63a5\u4ece\u5c3e\u90e8\u5f00\u59cb\u904d\u5386\u4e0d\u5c31\u597d\u4e86&#8230;\u53cd\u6b63\u90fd\u662f\u627e\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u3002\u4e0d\u8fc7\u8981\u8bb0\u5f97string\u7c7b\u578b\u7684\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u653e\u7684\u662f&#8217;\\0&#8217;\uff0c\u8bb0\u5f97\u53bb\u6389\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\r\npublic:\r\n    int lengthOfLastWord(string s) {\r\n       int len=s.length();\r\n       int wordLen=0;\r\n       for(int i=len-1;i!=-1;i--)\r\n       {\r\n           if(s&#91;i]!=' ')\r\n           {\r\n               cout&lt;&lt;s&#91;i]&lt;&lt;endl;\r\n               wordLen++;\r\n           }else if(s&#91;i]==' '&amp;&amp;wordLen!=0)\r\n           {\r\n               break;\r\n           }\r\n       }\r\n       return wordLen;\r\n    }\r\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u5b57\u7b26\u4e32<\/p>\n","protected":false},"author":1,"featured_media":2827,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2456"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=2456"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2456\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/2827"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=2456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=2456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=2456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}