{"id":2461,"date":"2022-03-24T10:49:00","date_gmt":"2022-03-24T02:49:00","guid":{"rendered":"https:\/\/www.zeroheart.xyz\/wordpress\/?p=2461"},"modified":"2022-03-24T10:52:53","modified_gmt":"2022-03-24T02:52:53","slug":"%e7%ae%97%e6%b3%95%e5%85%a5%e9%97%a8%e7%ac%ac-4-%e5%a4%a9","status":"publish","type":"post","link":"https:\/\/www.zeroheart.xyz\/wordpress\/?p=2461","title":{"rendered":"\u7b97\u6cd5\u5165\u95e8\u7b2c\u56db\u5929"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u53cc\u6307\u9488<\/h2>\n\n\n\n<p><a href=\"https:\/\/leetcode-cn.com\/study-plan\/algorithms\/?progress=7ob9vsg\">\u300c\u7b97\u6cd5\u300d &#8211; \u5b66\u4e60\u8ba1\u5212 &#8211; \u529b\u6263\uff08LeetCode\uff09\u5168\u7403\u6781\u5ba2\u631a\u7231\u7684\u6280\u672f\u6210\u957f\u5e73\u53f0 (leetcode-cn.com)<\/a><\/p>\n\n\n\n<p>\u8fd8\u662f\u57fa\u7840\u7ec3\u4e60\uff0c\u53cc\u6307\u9488\uff0c\u8fd9\u9898\u5c31\u662f\u4e8c\u5206\u6cd5\u7684\u90a3\u4e2a\u64cd\u4f5c<\/p>\n\n\n\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/reverse-string\/\">344. \u53cd\u8f6c\u5b57\u7b26\u4e32<\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><em>\/**<br><\/em><em> 344. \u53cd\u8f6c\u5b57\u7b26\u4e32<br><\/em><em> \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u5176\u4f5c\u7528\u662f\u5c06\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u53cd\u8f6c\u8fc7\u6765\u3002\u8f93\u5165\u5b57\u7b26\u4e32\u4ee5\u5b57\u7b26\u6570\u7ec4 s \u7684\u5f62\u5f0f\u7ed9\u51fa\u3002<br><\/em><em><br><\/em><em> \u4e0d\u8981\u7ed9\u53e6\u5916\u7684\u6570\u7ec4\u5206\u914d\u989d\u5916\u7684\u7a7a\u95f4\uff0c\u4f60\u5fc5\u987b\u539f\u5730\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u3001\u4f7f\u7528 O(1) \u7684\u989d\u5916\u7a7a\u95f4\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u3002<br><\/em><em><br><\/em><em><br><\/em><em><br><\/em><em> \u793a\u4f8b 1\uff1a<br><\/em><em><br><\/em><em> \u8f93\u5165\uff1as = [\"h\",\"e\",\"l\",\"l\",\"o\"]<br><\/em><em> \u8f93\u51fa\uff1a[\"o\",\"l\",\"l\",\"e\",\"h\"]<br><\/em><em> \u793a\u4f8b 2\uff1a<br><\/em><em><br><\/em><em> \u8f93\u5165\uff1as = [\"H\",\"a\",\"n\",\"n\",\"a\",\"h\"]<br><\/em><em> \u8f93\u51fa\uff1a[\"h\",\"a\",\"n\",\"n\",\"a\",\"H\"]<br><\/em><em><br><\/em><em><br><\/em><em> \u63d0\u793a\uff1a<br><\/em><em><br><\/em><em> 1 &lt;= s.length &lt;= 105<br><\/em><em> s[i] \u90fd\u662f ASCII \u7801\u8868\u4e2d\u7684\u53ef\u6253\u5370\u5b57\u7b26<br><\/em><em><br><\/em><em> * <\/em><strong><em>@author <\/em><\/strong><em>zeroheart<br><\/em><em> *<br><\/em><em> *\/<br><\/em>public class Question344 {<br>    public void reverseString(char[] s) {<br>        int low = 0;<br>        int high = s.length-1;<br>        while (low&lt;=high){<br>            char temp = s[low];<br>            s[low] = s[high];<br>            s[high] = temp;<br>            low++;<br>            high--;<br>        }<br>    }<br>}<\/pre>\n\n\n\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/reverse-words-in-a-string-iii\/\">557. \u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd III<\/a><\/p>\n\n\n\n<p>\u8fd9\u9898\u501f\u7528\u4e0a\u9762\u5199\u597d\u7684\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><em>\/**<br><\/em><em> 557. \u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd III<br><\/em><em> \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u4f60\u9700\u8981\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u6bcf\u4e2a\u5355\u8bcd\u7684\u5b57\u7b26\u987a\u5e8f\uff0c\u540c\u65f6\u4ecd\u4fdd\u7559\u7a7a\u683c\u548c\u5355\u8bcd\u7684\u521d\u59cb\u987a\u5e8f\u3002<br><\/em><em><br><\/em><em><br><\/em><em><br><\/em><em> \u793a\u4f8b 1\uff1a<br><\/em><em><br><\/em><em> \u8f93\u5165\uff1as = \"Let's take LeetCode contest\"<br><\/em><em> \u8f93\u51fa\uff1a\"s'teL ekat edoCteeL tsetnoc\"<br><\/em><em> \u793a\u4f8b 2:<br><\/em><em><br><\/em><em> \u8f93\u5165\uff1a s = \"God Ding\"<br><\/em><em> \u8f93\u51fa\uff1a\"doG gniD\"<br><\/em><em><br><\/em><em><br><\/em><em> \u63d0\u793a\uff1a<br><\/em><em><br><\/em><em> 1 &lt;= s.length &lt;= 5 * 10^4<br><\/em><em> s \u5305\u542b\u53ef\u6253\u5370\u7684 ASCII \u5b57\u7b26\u3002<br><\/em><em> s \u4e0d\u5305\u542b\u4efb\u4f55\u5f00\u5934\u6216\u7ed3\u5c3e\u7a7a\u683c\u3002<br><\/em><em> s \u91cc \u81f3\u5c11 \u6709\u4e00\u4e2a\u8bcd\u3002<br><\/em><em> s \u4e2d\u7684\u6240\u6709\u5355\u8bcd\u90fd\u7528\u4e00\u4e2a\u7a7a\u683c\u9694\u5f00\u3002<br><\/em><em><br><\/em><em> * <\/em><strong><em>@author <\/em><\/strong><em>zeroheart<br><\/em><em> *<br><\/em><em> *\/<br><\/em>public class Question557 {<br>    public String reverseWords(String s) {<br>        StringBuilder sb = new StringBuilder();<br>        String[] arr = s.split(\" \");<br>        for(int i=0; i&lt;arr.length; i++){<br>            String rs = reverseString(arr[i].toCharArray());<br>            sb.append(rs);<br>            if(i != arr.length - 1){<br>                sb.append(\" \");<br>            }<br>        }<br>        return new String(sb);<br>    }<br><br>    public String reverseString(char[] s) {<br>        int low = 0;<br>        int high = s.length-1;<br>        while (low&lt;=high){<br>            char temp = s[low];<br>            s[low] = s[high];<br>            s[high] = temp;<br>            low++;<br>            high--;<br>        }<br>        return new String(s);<br>    }<br>}<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53cc\u6307\u9488 \u300c\u7b97\u6cd5\u300d &#8211; \u5b66\u4e60\u8ba1\u5212 &#8211; \u529b\u6263\uff08LeetCode\uff09\u5168\u7403\u6781\u5ba2\u631a\u7231\u7684\u6280\u672f\u6210\u957f\u5e73\u53f0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[155],"tags":[157,161],"_links":{"self":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2461"}],"collection":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2461"}],"version-history":[{"count":10,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2461\/revisions"}],"predecessor-version":[{"id":2475,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2461\/revisions\/2475"}],"wp:attachment":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}