{"id":660,"date":"2020-06-20T00:51:15","date_gmt":"2020-06-19T16:51:15","guid":{"rendered":"http:\/\/www.guanhaobo.cn\/?p=660"},"modified":"2020-06-20T00:51:15","modified_gmt":"2020-06-19T16:51:15","slug":"jz2-%e6%9b%bf%e6%8d%a2%e7%a9%ba%e6%a0%bc","status":"publish","type":"post","link":"https:\/\/www.guanhaobo.cn\/?p=660","title":{"rendered":"JZ2 \u2014 \u66ff\u6362\u7a7a\u683c"},"content":{"rendered":"<h3>\u9898\u76ee\u63cf\u8ff0<\/h3>\n<p>\u8bf7\u5b9e\u73b0\u4e00\u4e2a\u51fd\u6570\uff0c\u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u7a7a\u683c\u66ff\u6362\u6210\u201c%20\u201d\u3002\u4f8b\u5982\uff0c\u5f53\u5b57\u7b26\u4e32\u4e3aWe Are Happy.\u5219\u7ecf\u8fc7\u66ff\u6362\u4e4b\u540e\u7684\u5b57\u7b26\u4e32\u4e3aWe%20Are%20Happy\u3002<\/p>\n<h3>\u9898\u76ee\u5206\u6790<\/h3>\n<p>\u5982\u679c\u53ef\u4ee5\u5f00\u8f9f\u65b0\u7684\u5b57\u7b26\u4e32\u6765\u8fdb\u884c\u8f85\u52a9\uff0c\u90a3\u4e48\u5f88\u7b80\u5355\uff0c\u5927\u5bb6\u90fd\u4f1a\u5199\u3002<br \/>\n\u6211\u4eec\u8fd9\u91cc\u8ba8\u8bba\u4e00\u4e0b\u5982\u4f55\u76f4\u63a5\u5728\u539f\u6765\u7684\u5b57\u7b26\u4e32\u4e0a\u8fdb\u884c\u4fee\u6539\u3002<\/p>\n<h3>C\/C++<\/h3>\n<p>\u4e3b\u8981\u601d\u8def\uff1a\u5148\u904d\u5386\u4e00\u904d\uff0c\u6570\u51fa\u7a7a\u683c\u7684\u4e2a\u6570\uff0c\u8ba1\u7b97\u51fa\u603b\u7684\u957f\u5ea6\u3002\u7136\u540e\u4ece\u540e\u5411\u524d\u904d\u5386\uff0c\u8c03\u6574\u5b57\u7b26\u4f4d\u7f6e\u3002\u4ece\u540e\u5411\u524d\u904d\u5386\uff0c\u6bcf\u4e2a\u5b57\u7b26\u53ea\u9700\u8981\u79fb\u52a8\u4e00\u6b21\u3002\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a<code>O(n)<\/code><br \/>\n\u6ce8\u610f\uff0c\u4f7f\u7528\u6b64\u51fd\u6570\u7684\u524d\u63d0\u662fstr\u6307\u9488\u5f00\u8f9f\u7684\u5185\u5b58\u7a7a\u95f4\u8db3\u591f\u5927\u3002<\/p>\n<pre><code class=\"language-cpp line-numbers\">class Solution\n{\npublic:\n    void replaceSpace(char *str, int length)\n    {\n        int count = 0;\n        for (int i = 0; i &lt; length; i++)\n            if (str[i] == ' ')\n                count++;\n        int len = length + 2 * count - 1;\n        for (int i = length - 1; i &gt;= 0; i--)\n        {\n            if (str[i] == ' ')\n            {\n                str[len] = '0';\n                str[len - 1] = '2';\n                str[len - 2] = '%';\n                len -= 3;\n            }\n            else\n            {\n                str[len] = str[i];\n                len--;\n            }\n        }\n        str[length + 2 * count] = '\\0';\n    }\n};\n<\/code><\/pre>\n<h3>Java<\/h3>\n<p>Java\u5b57\u7b26\u4e32\u5e26\u6709\u5f88\u591a\u65b9\u6cd5\uff0c\u6240\u4ee5\u5f88\u7b80\u5355\uff0c\u6bd4\u5982\u53ef\u4ee5\u76f4\u63a5\u7528<code>String<\/code>\u7c7b\u4e2d\u7684<code>replaceAll<\/code>\u65b9\u6cd5\u4e00\u884c\u641e\u5b9a\u3002\u4f46<code>String<\/code>\u5bf9\u8c61\u672c\u8eab\u662f\u4e0d\u4f1a\u88ab\u6539\u53d8\u7684\uff0c\u76f8\u5173\u7684\u65b9\u6cd5\u53ea\u662f\u8fd4\u56de\u4e86\u4e00\u4e2a\u65b0\u7684<code>String<\/code>\u5bf9\u8c61\u3002<br \/>\n\u4e3b\u8981\u601d\u8def\uff1a\u5220\u9664\u7a7a\u683c\uff0c\u7136\u540e\u63d2\u5165<code>%20<\/code><\/p>\n<pre><code class=\"language-java line-numbers\">public class Solution {\n    public String replaceSpace(StringBuffer str) {\n        for (int i = 0; i &lt; str.length(); i++) {\n            if (str.charAt(i) == ' ') {\n                str.deleteCharAt(i);\n                str.insert(i, \"%20\");\n                i += 2;\n            }\n        }\n        return str.toString();\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u63cf\u8ff0 \u8bf7\u5b9e\u73b0\u4e00\u4e2a\u51fd\u6570\uff0c\u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u7a7a\u683c\u66ff\u6362\u6210\u201c%20\u201d\u3002\u4f8b\u5982\uff0c\u5f53\u5b57\u7b26\u4e32\u4e3aWe Are Happy. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[39],"class_list":["post-660","post","type-post","status-publish","format-standard","hentry","category-algo","tag-offer"],"_links":{"self":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=660"}],"version-history":[{"count":0,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/660\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}