{"id":108,"date":"2026-09-08T16:52:02","date_gmt":"2026-09-08T08:52:02","guid":{"rendered":"https:\/\/www.rainyblue.cn\/?p=108"},"modified":"2026-09-08T16:52:02","modified_gmt":"2026-09-08T08:52:02","slug":"%e5%8f%8c%e6%8c%87%e9%92%88%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.rainyblue.cn\/index.php\/2026\/09\/08\/%e5%8f%8c%e6%8c%87%e9%92%88%e9%97%ae%e9%a2%98\/","title":{"rendered":"\u53cc\u6307\u9488\u95ee\u9898"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">26.\u5220\u9664\u6709\u5e8f\u6570\u7ec4\u7684\u91cd\u590d\u9879<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u4f60\u4e00\u4e2a <strong>\u975e\u4e25\u683c\u9012\u589e\u6392\u5217<\/strong> \u7684\u6570\u7ec4 <code>nums<\/code> \uff0c\u8bf7\u4f60 <strong><a href=\"http:\/\/baike.baidu.com\/item\/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95\">\u539f\u5730<\/a><\/strong> \u5220\u9664\u91cd\u590d\u51fa\u73b0\u7684\u5143\u7d20\uff0c\u4f7f\u6bcf\u4e2a\u5143\u7d20 <strong>\u53ea\u51fa\u73b0\u4e00\u6b21<\/strong> \uff0c\u8fd4\u56de\u5220\u9664\u540e\u6570\u7ec4\u7684\u65b0\u957f\u5ea6\u3002\u5143\u7d20\u7684 <strong>\u76f8\u5bf9\u987a\u5e8f<\/strong> \u5e94\u8be5\u4fdd\u6301 <strong>\u4e00\u81f4<\/strong> \u3002\u7136\u540e\u8fd4\u56de <code>nums<\/code> \u4e2d\u552f\u4e00\u5143\u7d20\u7684\u4e2a\u6570<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;class Solution {<br>&nbsp;public:<br>&nbsp; &nbsp; &nbsp;int removeDuplicates(vector&lt;int&gt;&amp; nums) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int slowidx = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(int fastidx = 0;fastidx &lt; nums.size();fastidx++){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(nums[fastidx]!=nums[slowidx]){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;slowidx++;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nums[slowidx]=nums[fastidx];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return slowidx+1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  }<br>&nbsp;};<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">283.\u79fb\u9664\u96f6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 <code>nums<\/code>\uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u5c06\u6240\u6709 <code>0<\/code> \u79fb\u52a8\u5230\u6570\u7ec4\u7684\u672b\u5c3e\uff0c\u540c\u65f6\u4fdd\u6301\u975e\u96f6\u5143\u7d20\u7684\u76f8\u5bf9\u987a\u5e8f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bf7\u6ce8\u610f<\/strong> \uff0c\u5fc5\u987b\u5728\u4e0d\u590d\u5236\u6570\u7ec4\u7684\u60c5\u51b5\u4e0b\u539f\u5730\u5bf9\u6570\u7ec4\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;class Solution {<br>&nbsp;public:<br>&nbsp; &nbsp; &nbsp;void moveZeroes(vector&lt;int&gt;&amp; nums) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int slow = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(int fast = 0;fast&lt;nums.size();fast++){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(nums[fast] != 0){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;swap(nums[slow],nums[fast]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;slow++;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp;  }<br>&nbsp;};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u592a\u597d\u4e86\u662f\u4ea4\u6362\u51fd\u6570<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">844.\u6bd4\u8f83\u542b\u9000\u683c\u7684\u5b57\u7b26\u4e32<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u5b9a <code>s<\/code> \u548c <code>t<\/code> \u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u5f53\u5b83\u4eec\u5206\u522b\u88ab\u8f93\u5165\u5230\u7a7a\u767d\u7684\u6587\u672c\u7f16\u8f91\u5668\u540e\uff0c\u5982\u679c\u4e24\u8005\u76f8\u7b49\uff0c\u8fd4\u56de <code>true<\/code> \u3002<code>#<\/code> \u4ee3\u8868\u9000\u683c\u5b57\u7b26\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\uff1a<\/strong>\u5982\u679c\u5bf9\u7a7a\u6587\u672c\u8f93\u5165\u9000\u683c\u5b57\u7b26\uff0c\u6587\u672c\u7ee7\u7eed\u4e3a\u7a7a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;\u8f93\u5165\uff1as = \"ab#c\", t = \"ad#c\"<br>&nbsp;\u8f93\u51fa\uff1atrue<br>&nbsp;\u89e3\u91ca\uff1as \u548c t \u90fd\u4f1a\u53d8\u6210 \"ac\"\u3002<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;\u8f93\u5165\uff1as = \"ab##\", t = \"c#d#\"<br>&nbsp;\u8f93\u51fa\uff1atrue<br>&nbsp;\u89e3\u91ca\uff1as \u548c t \u90fd\u4f1a\u53d8\u6210 \"\"\u3002<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;\u8f93\u5165\uff1as = \"a#c\", t = \"b\"<br>&nbsp;\u8f93\u51fa\uff1afalse<br>&nbsp;\u89e3\u91ca\uff1as \u4f1a\u53d8\u6210 \"c\"\uff0c\u4f46 t \u4ecd\u7136\u662f \"b\"\u3002<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>1 &lt;= s.length, t.length &lt;= 200<\/code><\/li>\n\n\n\n<li><code>s<\/code> \u548c <code>t<\/code> \u53ea\u542b\u6709\u5c0f\u5199\u5b57\u6bcd\u4ee5\u53ca\u5b57\u7b26 <code>'#'<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e00\uff1a\u91cd\u6784\u5b57\u7b26\u4e32\uff08\u6808\uff09<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u904d\u5386\u539f\u5b57\u7b26\u4e32\uff0c\u9047\u5230\u975e\u9000\u683c\u7b26\u5219\u5728\u65b0\u5b57\u7b26\u4e32\u672b\u5c3e\u63d2\u5165\u8be5\u5b57\u7b26\uff0c\u9047\u5230\u9000\u683c\u7b26\u5219\u5220\u9664\u65b0\u5b57\u7b26\u4e32\u672b\u5c3e\u7684\u5143\u7d20\uff08\u5220\u9664\u5143\u7d20\u524d\u9700\u5224\u7a7a\uff09<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;class Solution {<br>&nbsp;public:<br>&nbsp; &nbsp; &nbsp;bool backspaceCompare(string s, string t) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return build(s) == build(t);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  }<br>&nbsp;\u200b<br>&nbsp; &nbsp; &nbsp;string build(string str){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string ret;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(char ch : str){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(ch != '#'){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ret.push_back(ch);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else if(ret.size() != 0){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ret.pop_back();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return ret;<br>&nbsp; &nbsp;  }<br>&nbsp;};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u65f6\u95f4\u590d\u6742\u5ea6\uff1aO(N+M)\uff0c\u5176\u4e2d N \u548c M \u5206\u522b\u4e3a\u5b57\u7b26\u4e32 S \u548c T \u7684\u957f\u5ea6\u3002\u6211\u4eec\u9700\u8981\u904d\u5386\u4e24\u5b57\u7b26\u4e32\u5404\u4e00\u6b21\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a7a\u95f4\u590d\u6742\u5ea6\uff1aO(N+M)\uff0c\u5176\u4e2d N \u548c M \u5206\u522b\u4e3a\u5b57\u7b26\u4e32 S \u548c T \u7684\u957f\u5ea6\u3002\u4e3b\u8981\u4e3a\u8fd8\u539f\u51fa\u7684\u5b57\u7b26\u4e32\u7684\u5f00\u9500\u3002 \u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/backspace-string-compare\/solutions\/451606\/bi-jiao-han-tui-ge-de-zi-fu-chuan-by-leetcode-solu\/\">https:\/\/leetcode.cn\/problems\/backspace-string-compare\/solutions\/451606\/bi-jiao-han-tui-ge-de-zi-fu-chuan-by-leetcode-solu\/<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e8c\uff1a\u53cc\u6307\u9488\u6cd5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u4e2a\u5b57\u7b26\u662f\u5426\u4f1a\u88ab\u5220\u6389\uff0c\u53ea\u53d6\u51b3\u4e8e\u8be5\u5b57\u7b26\u540e\u9762\u7684\u9000\u683c\u7b26\uff0c\u800c\u4e0e\u8be5\u5b57\u7b26\u524d\u9762\u7684\u9000\u683c\u7b26\u65e0\u5173\u3002\u56e0\u6b64\u5f53\u6211\u4eec\u9006\u5e8f\u5730\u904d\u5386\u5b57\u7b26\u4e32\uff0c\u5c31\u53ef\u4ee5\u7acb\u5373\u786e\u5b9a\u5f53\u524d\u5b57\u7b26\u662f\u5426\u4f1a\u88ab\u5220\u6389\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5177\u4f53\u5730\uff0c\u6211\u4eec\u5b9a\u4e49 skip \u8868\u793a\u5f53\u524d\u5f85\u5220\u9664\u7684\u5b57\u7b26\u7684\u6570\u91cf\u3002\u6bcf\u6b21\u6211\u4eec\u904d\u5386\u5230\u4e00\u4e2a\u5b57\u7b26\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8be5\u5b57\u7b26\u4e3a\u9000\u683c\u7b26\uff0c\u5219\u6211\u4eec\u9700\u8981\u591a\u5220\u9664\u4e00\u4e2a\u666e\u901a\u5b57\u7b26\uff0c\u6211\u4eec\u8ba9 skip \u52a0 1\uff0ci&#8211;\uff08\u5220\u53bb\u9000\u683c\u7b26\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8be5\u5b57\u7b26\u4e3a\u666e\u901a\u5b57\u7b26\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5 skip \u4e3a 0\uff0c\u5219\u8bf4\u660e\u5f53\u524d\u5b57\u7b26\u4e0d\u9700\u8981\u5220\u53bb\uff1b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5 skip \u4e0d\u4e3a 0\uff0c\u5219\u8bf4\u660e\u5f53\u524d\u5b57\u7b26\u9700\u8981\u5220\u53bb\uff0c\u6211\u4eec\u8ba9 skip \u51cf 1\uff0ci&#8211;\uff08\u5220\u53bb\u65e0\u6548\u5b57\u7b26\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u6837\uff0c\u6211\u4eec\u5b9a\u4e49\u4e24\u4e2a\u6307\u9488\uff0c\u5206\u522b\u6307\u5411\u4e24\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002\u6bcf\u6b21\u6211\u4eec\u8ba9\u4e24\u6307\u9488\u9006\u5e8f\u5730\u904d\u5386\u4e24\u5b57\u7b26\u4e32\uff0c\u76f4\u5230\u4e24\u5b57\u7b26\u4e32\u80fd\u591f\u5404\u81ea\u786e\u5b9a\u4e00\u4e2a\u5b57\u7b26\uff0c\u7136\u540e\u5c06\u8fd9\u4e24\u4e2a\u5b57\u7b26\u8fdb\u884c\u6bd4\u8f83\u3002\u91cd\u590d\u8fd9\u4e00\u8fc7\u7a0b\u76f4\u5230\u627e\u5230\u7684\u4e24\u4e2a\u5b57\u7b26\u4e0d\u76f8\u7b49\uff0c\u6216\u904d\u5386\u5b8c\u5b57\u7b26\u4e32\u4e3a\u6b62\u3002 \u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/backspace-string-compare\/solutions\/451606\/bi-jiao-han-tui-ge-de-zi-fu-chuan-by-leetcode-solu\/\">https:\/\/leetcode.cn\/problems\/backspace-string-compare\/solutions\/451606\/bi-jiao-han-tui-ge-de-zi-fu-chuan-by-leetcode-solu\/<\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5916\u5c42 <code>while<\/code> \u5faa\u73af\u7684\u6bcf\u4e00\u6b21\u8fed\u4ee3\uff0c\u5c31\u662f<strong>\u4ece\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e2d\u5404\u627e\u5230\u4e00\u4e2a\u6709\u6548\u5b57\u7b26\uff0c\u7136\u540e\u6bd4\u8f83\u5b83\u4eec<\/strong>\u3002<\/li>\n\n\n\n<li>\u5185\u5c42\u5faa\u73af\u7528\u4e8e\u627e\u5230\u6709\u6548\u5b57\u7b26\uff08i\uff0cj\u6307\u5411\u6709\u6548\u5b57\u7b26\uff09<\/li>\n\n\n\n<li>\u5185\u5c42\u4e8c\u4e2afor\u5faa\u73af\u540e\u5c31\u627e\u5230\u4e86\u6709\u6548\u5b57\u7b26\uff0c\u7136\u540e\u8fdb\u884c\u6bd4\u8f83\u5224\u65ad\n<ul class=\"wp-block-list\">\n<li>\u4e8c\u4e2a\u5b57\u7b26\u4e32\u90fd\u6ca1\u904d\u5386\u5b8c\uff1a\u5f53\u6709\u6548\u5b57\u7b26\u4e0d\u76f8\u7b49\uff0c\u8bf4\u660e\u6574\u4e2a\u6709\u6548\u5b57\u7b26\u4e32\u4e0d\u76f8\u7b49\uff0c\u8fd4\u56defalse\u3002\u5f53\u6709\u6548\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u8fdb\u5165\u4e0b\u4e00\u6b21\u5faa\u73af<\/li>\n\n\n\n<li>\u4e00\u4e2a\u5b57\u7b26\u4e32\u904d\u5386\u5b8c\uff0c\u53e6\u4e00\u4e2a\u6ca1\u6709\u904d\u5386\u5b8c\uff1a\u8bf4\u660e\u6709\u6548\u5b57\u7b26\u4e32\u957f\u5ea6\u4e0d\u7b49\uff0c\u65e0\u9700\u518d\u5224\u65ad\uff0c\u76f4\u63a5\u8fd4\u56defalse<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>i&#8211;\uff0cj&#8211;\uff0c\u8fdb\u5165\u4e0b\u4e00\u6b21\u5916\u5c42\u5faa\u73af<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;class Solution {<br>&nbsp;public:<br>&nbsp; &nbsp; &nbsp;bool backspaceCompare(string s, string t) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int i = s.size()-1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int j = t.size()-1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int skips = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int skipt = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while(i &gt;= 0 || &nbsp;j&gt;= 0){<br>&nbsp;\u200b<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/\u4e0b\u9762\u4e8c\u4e2afor\u5faa\u73af\u4e3a\u4e86\u627e\u5230\u4e8c\u4e2a\u5b57\u7b26\u4e32\u5404\u81ea\u7684\u6709\u6548\u5b57\u7b26\uff08\u4ece\u540e\u5f80\u524d\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while(i &gt;= 0){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(s[i] == '#'){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i--;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;skips++;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else if(skips&gt;0){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;skips--;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i--;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp;\u200b<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while(j &gt;= 0){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(t[j] == '#'){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;j--;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;skipt++;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else if(skipt&gt;0){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;skipt--;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;j--;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp;\u200b<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/\u5982\u679c\u90fd\u6ca1\u904d\u5386\u5b8c\uff0c\u8bf4\u660e\u76ee\u524d\u6709\u6548\u5b57\u7b26\u4e00\u6837\u957f\uff0c\u4e8c\u4e2a\u6709\u6548\u5b57\u7b26\u8fdb\u884c\u6bd4\u8f83\uff0c\u4e0d\u76f8\u540c\u8fd4\u56defalse<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(i &gt;=0 &amp;&amp;j &gt;= 0){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(s[i] != t[j]){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/\u5982\u679c\u6709\u4e00\u4e32\u5b57\u7b26\u4e32\u5df2\u7ecf\u904d\u5386\u5b8c\uff0c\u53e6\u4e00\u4e32\u8fd8\u6ca1\u6709\uff0c\u8bf4\u660e\u6709\u6548\u5b57\u7b26\u957f\u5ea6\u4e0d\u4e00\u6837\uff0c\u4e0d\u53ef\u80fd\u76f8\u7b49\uff0c\u8fd4\u56defalse<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(i &gt;= 0 || j &gt;= 0){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp;\u200b<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/\u627e\u5230\u4e86\u4e00\u4e2a\u6709\u6548\u5b57\u7b26\u540e\uff0c\u63a5\u7740\u627e\u4e0b\u4e00\u4e2a\u6709\u6548\u5b57\u7b26\uff08\u5916\u5c42\u5faa\u73af\u4e00\u6b21\u5c31\u76f8\u5f53\u4e8e\u627e\u5230\u4e00\u4e2a\u6709\u6548\u5b57\u7b26\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i--;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;j--;<br>&nbsp;\u200b<br>&nbsp;\u200b<br>&nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  }<br>&nbsp;\u200b<br>&nbsp;};<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">977.\u6709\u5e8f\u6570\u7ec4\u7684\u5e73\u65b9<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u4f60\u4e00\u4e2a\u6309 <strong>\u975e\u9012\u51cf\u987a\u5e8f<\/strong> \u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 <code>nums<\/code>\uff0c\u8fd4\u56de <strong>\u6bcf\u4e2a\u6570\u5b57\u7684\u5e73\u65b9<\/strong> \u7ec4\u6210\u7684\u65b0\u6570\u7ec4\uff0c\u8981\u6c42\u4e5f\u6309 <strong>\u975e\u9012\u51cf\u987a\u5e8f<\/strong> \u6392\u5e8f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;\u8f93\u5165\uff1anums = [-4,-1,0,3,10]<br>&nbsp;\u8f93\u51fa\uff1a[0,1,9,16,100]<br>&nbsp;\u89e3\u91ca\uff1a\u5e73\u65b9\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [16,1,0,9,100]<br>&nbsp;\u6392\u5e8f\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [0,1,9,16,100]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;\u8f93\u5165\uff1anums = [-7,-3,2,3,11]<br>&nbsp;\u8f93\u51fa\uff1a[4,9,9,49,121]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>1 &lt;= nums.length &lt;= 104<\/code><\/li>\n\n\n\n<li><code>-104 &lt;= nums[i] &lt;= 104<\/code><\/li>\n\n\n\n<li><code>nums<\/code> \u5df2\u6309 <strong>\u975e\u9012\u51cf\u987a\u5e8f<\/strong> \u6392\u5e8f<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8fdb\u9636\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8bf7\u4f60\u8bbe\u8ba1\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a <code>O(n)<\/code> \u7684\u7b97\u6cd5\u89e3\u51b3\u672c\u95ee\u9898<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e00\uff1a\u5feb\u901f\u6392\u5e8f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u628a\u5404\u5143\u7d20\u5e73\u65b9\u653e\u5230\u65b0\u6570\u7ec4\uff0c\u518d\u7528\u5feb\u6392\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;class Solution {<br>&nbsp;public:<br>&nbsp; &nbsp; &nbsp;vector&lt;int&gt; sortedSquares(vector&lt;int&gt;&amp; nums) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;vector&lt;int&gt;ans;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(int num:nums){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ans.push_back(num * num);<br>&nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sort(ans.begin(),ans.end());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return ans;<br>&nbsp; &nbsp;  }<br>&nbsp;};<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u65f6\u95f4\u590d\u6742\u5ea6\uff1aO(nlogn)\uff0c\u5176\u4e2d n \u662f\u6570\u7ec4 nums \u7684\u957f\u5ea6\u3002<\/li>\n\n\n\n<li>\u7a7a\u95f4\u590d\u6742\u5ea6\uff1aO(logn)\u3002\u9664\u4e86\u5b58\u50a8\u7b54\u6848\u7684\u6570\u7ec4\u4ee5\u5916\uff0c\u6211\u4eec\u9700\u8981 O(logn) \u7684\u6808\u7a7a\u95f4\u8fdb\u884c\u6392\u5e8f\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e8c\uff1a\u53cc\u6307\u9488<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528\u4e24\u4e2a\u6307\u9488\u5206\u522b\u6307\u5411\u4f4d\u7f6e 0 \u548c <em>n<\/em>\u22121\uff0c\u6bcf\u6b21\u6bd4\u8f83\u4e24\u4e2a\u6307\u9488\u5bf9\u5e94\u7684\u6570\uff0c\u9009\u62e9\u8f83\u5927\u7684\u90a3\u4e2a<strong>\u9006\u5e8f<\/strong>\u653e\u5165ans\u5bb9\u5668\u5e76\u79fb\u52a8\u6307\u9488\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;class Solution {<br>&nbsp;public:<br>&nbsp; &nbsp; &nbsp;vector&lt;int&gt; sortedSquares(vector&lt;int&gt;&amp; nums) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int n = nums.size();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;vector&lt;int&gt;ans(n);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int i = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int j = n-1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int pos = j;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while(i &lt;= j){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(nums[i]*nums[i] &lt; nums[j]*nums[j]){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ans[pos] = nums[j]*nums[j];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;j--;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ans[pos] = nums[i]*nums[i];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i++;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pos--;<br>&nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return ans;<br>&nbsp; &nbsp;  }<br>&nbsp;};<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u65f6\u95f4\u590d\u6742\u5ea6\uff1a<em>O<\/em>(<em>n<\/em>)\uff0c\u5176\u4e2d <em>n<\/em> \u662f\u6570\u7ec4 <em>nums<\/em> \u7684\u957f\u5ea6\u3002<\/li>\n\n\n\n<li>\u7a7a\u95f4\u590d\u6742\u5ea6\uff1a<em>O<\/em>(1)\u3002\u9664\u4e86\u5b58\u50a8\u7b54\u6848\u7684\u6570\u7ec4\u4ee5\u5916\uff0c\u6211\u4eec\u53ea\u9700\u8981\u7ef4\u62a4\u5e38\u91cf\u7a7a\u95f4\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u52a8\u753b\u6f14\u793a\uff1a<a href=\"https:\/\/www.bilibili.com\/video\/BV1bBBxY4EGu?spm_id_from=333.788.videopod.sections&amp;vd_source=037f9dc16386b621c820966042061202\">\u3010LeetCode\u3011\u3010Manim\u52a8\u753b\u3011977. \u6709\u5e8f\u6570\u7ec4\u7684\u5e73\u65b9<em>\u54d4\u54e9\u54d4\u54e9<\/em>bilibili<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>26.\u5220\u9664\u6709\u5e8f\u6570\u7ec4\u7684\u91cd\u590d\u9879 \u7ed9\u4f60\u4e00\u4e2a \u975e\u4e25\u683c\u9012\u589e\u6392\u5217 \u7684\u6570\u7ec4 nums \uff0c\u8bf7\u4f60 \u539f\u5730 \u5220\u9664\u91cd\u590d\u51fa\u73b0\u7684\u5143\u7d20\uff0c\u4f7f\u6bcf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":82,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-108","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-study1"],"_links":{"self":[{"href":"https:\/\/www.rainyblue.cn\/index.php\/wp-json\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rainyblue.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rainyblue.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rainyblue.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rainyblue.cn\/index.php\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":1,"href":"https:\/\/www.rainyblue.cn\/index.php\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":109,"href":"https:\/\/www.rainyblue.cn\/index.php\/wp-json\/wp\/v2\/posts\/108\/revisions\/109"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rainyblue.cn\/index.php\/wp-json\/wp\/v2\/media\/82"}],"wp:attachment":[{"href":"https:\/\/www.rainyblue.cn\/index.php\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rainyblue.cn\/index.php\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rainyblue.cn\/index.php\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}