{"id":166,"date":"2024-10-16T18:26:32","date_gmt":"2024-10-16T10:26:32","guid":{"rendered":"https:\/\/womeifei.cn\/?p=166"},"modified":"2024-10-16T18:26:32","modified_gmt":"2024-10-16T10:26:32","slug":"%e5%8f%8c%e7%ab%af%e9%98%9f%e5%88%97%e5%ae%9e%e7%8e%b0%e6%bb%9a%e5%8a%a8%e7%aa%97%e5%8f%a3%e6%9c%80%e5%a4%a7%e5%80%bc","status":"publish","type":"post","link":"https:\/\/womeifei.cn\/index.php\/2024\/10\/16\/%e5%8f%8c%e7%ab%af%e9%98%9f%e5%88%97%e5%ae%9e%e7%8e%b0%e6%bb%9a%e5%8a%a8%e7%aa%97%e5%8f%a3%e6%9c%80%e5%a4%a7%e5%80%bc\/","title":{"rendered":"\u53cc\u7aef\u961f\u5217\u5b9e\u73b0\u6eda\u52a8\u7a97\u53e3\u6700\u5927\u503c"},"content":{"rendered":"\n<p>\u57fa\u672c\u8868\u73b0\u5f62\u5f0f\u5982\u4e0b<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/womeifei.cn\/wp-content\/uploads\/2024\/10\/image-16.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"921\" height=\"876\" data-original=\"https:\/\/womeifei.cn\/wp-content\/uploads\/2024\/10\/image-16.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-167\"  sizes=\"auto, (max-width: 921px) 100vw, 921px\" \/><\/div><\/figure>\n\n\n\n<p>\u5229\u7528\u53cc\u7aef\u961f\u5217  \u4fdd\u8bc1\u961f\u5217\u5185\u90e8\u9012\u51cf \u961f\u9996\u5143\u7d20\u5373\u4e3a\u6700\u5927\u503c<\/p>\n\n\n\n<p>C\u8bed\u8a00\u786e\u5b9e\u6bd4C++\u9ebb\u70e6\u4e0d\u5c11 \u6e90\u4ee3\u7801\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#define _CRT_SECURE_NO_WARNINGS\n#include&lt;stdio.h>\n#include&lt;stdlib.h>\n\/\/\u7ed3\u70b9\u7ed3\u6784\u4f53\ntypedef struct Node \n{\n\tint value;\n\tstruct Node* next;\n}Node;\n\/\/\u53cc\u7aef\u961f\u5217\u7ed3\u6784\u4f53\ntypedef struct MyQueue\n{\n\tNode* front;\n\tNode* rear;\n}MyQueue;\n\/\/\u521d\u59cb\u5316\u53cc\u7aef\u961f\u5217\nMyQueue* creatQueue()\n{\n\tMyQueue* Queue=(MyQueue*)malloc(sizeof(MyQueue));\n\tQueue->rear = NULL;\n\tQueue->front = NULL;\n\treturn Queue;\n}\n\/\/\u653e\u7f6e\u7ed3\u70b9\u5728\u961f\u5c3e(\u4fdd\u8bc1\u9012\u51cf!)\nvoid Push(MyQueue* queue, int val)\n{\n\tNode* newNode = (Node*)malloc(sizeof(Node));\n\tnewNode->value = val;\n\tnewNode->next = NULL;\n\n\tif (queue->rear == NULL)\n\t{\n\t\tqueue->rear = newNode;\n\t\tqueue->front = newNode;\n\t}\n\telse\n\t{\n\t\tqueue->rear->next = newNode;\n\t\tqueue->rear = newNode;\n\t}\n\n\tNode* curr = queue->front;\n\tNode* prev = NULL;\n\twhile (curr != NULL &amp;&amp; curr->value &lt; val)\n\t{\n\t\tNode* temp = curr;    \/\/ \u5b58\u50a8\u5f53\u524d\u8282\u70b9\u4ee5\u4fbf\u7a0d\u540e\u91ca\u653e\u5185\u5b58\n\t\tcurr = curr->next;    \/\/ \u79fb\u52a8\u5230\u4e0b\u4e00\u4e2a\u8282\u70b9\n\t\tfree(temp);           \/\/ \u91ca\u653e\u5f53\u524d\u8282\u70b9\u7684\u5185\u5b58\n\t\tif (prev == NULL)     \/\/ \u5982\u679c\u8fd9\u662f\u7b2c\u4e00\u4e2a\u8282\u70b9\n\t\t\tqueue->front = curr; \/\/ \u66f4\u65b0\u961f\u5217\u7684\u524d\u7aef\n\t\telse\n\t\t\tprev->next = curr; \/\/ \u5c06\u524d\u4e00\u4e2a\u8282\u70b9\u94fe\u63a5\u5230\u5f53\u524d\u8282\u70b9\n\t}\n\tif (curr == NULL)queue->rear = prev;   \/\/ \u5982\u679c curr \u4e3a NULL\uff0c\u66f4\u65b0\u961f\u5217\u7684\u540e\u7aef\n}\n\/\/\u5220\u9664\u65e7\u6846\u7ed3\u70b9\nvoid Pop(MyQueue* queue,int val)\n{\n\tif (queue->front != NULL &amp;&amp; queue->front->value == val)\n\t{\n\t\tNode* temp = queue->front;\n\t\tqueue->front = queue->front->next;\n\t\tif (queue->front == NULL)queue->rear = NULL;\n\t\tfree(temp);\n\t}\n}\n\/\/\u83b7\u53d6\u6700\u5927\u5143\u7d20\nint front(MyQueue* queue)\n{\n\treturn (queue->front != NULL) ? queue->front->value : -1;\n}\n\/\/\u6e05\u7a7a\u961f\u5217\nvoid freeQueue(MyQueue* queue)\n{\n\tNode* curr = queue->front;\n\twhile (curr!=NULL)\n\t{\n\t\tNode* temp = curr;\n\t\tcurr = curr->next;\n\t\tfree(temp);\n\t}\n\tfree(queue);\n}\n\/\/\u83b7\u5f97\u7a97\u53e3\u6700\u5927\u503c\u6570\u7ec4\n\/\/\u7528returnSize\u76f4\u63a5\u83b7\u53d6\u76ee\u6807\u6570\u7ec4\u5927\u5c0f \u5f88\u65b9\u4fbf\nint* maxSlidingWindow(int* nums, int numsSize, int k, int* returnSize)\n{\n\tMyQueue* que = creatQueue();\n\t\/\/n\u5143\u7d20 k\u5927\u5c0f\u7684\u6846 \u4e00\u5171\u4f1a\u51fa\u73b0n-k+1\u4e2a\u7a97\u53e3\n\tint* res = (int*)malloc((numsSize - k + 1) * sizeof(int));\n\t*returnSize = 0;\n\tint left = 0, right = 0;\n\t\/\/\u521d\u59cb\u5316\u4e00\u4e0b\u524d\u9762\u7684k\u4e2a\u7ec4\u6210\u7684\u7a97\u53e3\n\twhile (right &lt; k)\n\t{\n\t\tPush(que, nums&#91;right++]);\n\t}\n\tres&#91;(*returnSize)++] = front(que);\n\t\/\/\u8fd9\u4e4b\u540e\u5de6\u8fb9\u754c\u79fb\u52a8 \u5220\u9664\u65e7\u7a97\u53e3\u5143\u7d20\n\twhile (right&lt;numsSize)\n\t{\n\t\tPush(que, nums&#91;right++]);\n\t\tPop(que, nums&#91;left++]);\n\t\tres&#91;(*returnSize)++] = front(que);\n\t}\n\tfreeQueue(que);\n\treturn res;\n}\nint main()\n{\n\tint nums&#91;] = { 1,3,-1,-3,5,3,6,7 };\n\tint k = 3;\n\tint returnSize;\n\tint* result = maxSlidingWindow(nums, sizeof(nums) \/ sizeof(nums&#91;0]), k, &amp;returnSize);\n\tfor (int i = 0; i &lt; returnSize; i++) \n\t{\n\t\tprintf(\"\u5f53\u524d\u7a97\u53e3%d\u7684\u6700\u5927\u503c\u4e3a%d\\n\", i + 1, result&#91;i]);\n\t}\n\tfree(result);\n\treturn 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u8868\u73b0\u5f62\u5f0f\u5982\u4e0b \u5229\u7528\u53cc\u7aef\u961f\u5217 \u4fdd\u8bc1\u961f\u5217\u5185\u90e8\u9012\u51cf \u961f\u9996\u5143\u7d20\u5373\u4e3a\u6700\u5927\u503c C\u8bed\u8a00\u786e\u5b9e\u6bd4C++\u9ebb\u70e6\u4e0d\u5c11 \u6e90\u4ee3\u7801\u5982\u4e0b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6,7],"tags":[],"class_list":["post-166","post","type-post","status-publish","format-standard","hentry","category-4","category-6","category-7"],"_links":{"self":[{"href":"https:\/\/womeifei.cn\/index.php\/wp-json\/wp\/v2\/posts\/166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/womeifei.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/womeifei.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/womeifei.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/womeifei.cn\/index.php\/wp-json\/wp\/v2\/comments?post=166"}],"version-history":[{"count":1,"href":"https:\/\/womeifei.cn\/index.php\/wp-json\/wp\/v2\/posts\/166\/revisions"}],"predecessor-version":[{"id":168,"href":"https:\/\/womeifei.cn\/index.php\/wp-json\/wp\/v2\/posts\/166\/revisions\/168"}],"wp:attachment":[{"href":"https:\/\/womeifei.cn\/index.php\/wp-json\/wp\/v2\/media?parent=166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/womeifei.cn\/index.php\/wp-json\/wp\/v2\/categories?post=166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/womeifei.cn\/index.php\/wp-json\/wp\/v2\/tags?post=166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}