{"id":110361,"date":"2026-09-26T19:09:13","date_gmt":"2026-09-26T11:09:13","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/110361.html"},"modified":"2026-09-26T19:09:13","modified_gmt":"2026-09-26T11:09:13","slug":"hot-100-%e5%a4%9a%e6%95%b0%e5%85%83%e7%b4%a0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/110361.html","title":{"rendered":"Hot 100 --- \u591a\u6570\u5143\u7d20"},"content":{"rendered":"<p>\u672c\u6587\u6982\u89c8&#xff1a;\u672c\u6587\u8bb2\u89e3\u591a\u6570\u5143\u7d20&#xff1a;\u591a\u6570\u5143\u7d20\u51fa\u73b0\u6b21\u6570\u8d85\u8fc7 n\/2&#xff0c;\u6240\u4ee5\u6392\u5e8f\u540e\u4e0b\u6807 n\/2 \u7684\u4f4d\u7f6e\u4e00\u5b9a\u662f\u5b83&#xff1b;\u66f4\u4f18\u7684\u6469\u5c14\u6295\u7968\u6cd5\u628a\u95ee\u9898\u770b\u6210&#034;\u4e24\u4e24\u62b5\u6d88&#034;&#xff0c;\u56e0\u4e3a\u591a\u6570\u5143\u7d20\u7684\u603b\u6570\u8d85\u8fc7\u5176\u4f59\u5143\u7d20\u4e4b\u548c&#xff0c;\u62b5\u6d88\u5230\u6700\u540e\u5269\u4e0b\u7684\u5c31\u662f\u5b83&#xff0c;O(n) \u65f6\u95f4\u3001O(1) \u7a7a\u95f4<\/p>\n<hr \/>\n<h4>\u4e00\u3001\u9898\u76ee<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260926110911-6ab7a7d71bea4.png\" alt=\"\u5916\u94fe\u56fe\u7247\u8f6c\u5b58\u5931\u8d25,\u6e90\u7ad9\u53ef\u80fd\u6709\u9632\u76d7\u94fe\u673a\u5236,\u5efa\u8bae\u5c06\u56fe\u7247\u4fdd\u5b58\u4e0b\u6765\u76f4\u63a5\u4e0a\u4f20\" \/><\/p>\n<hr \/>\n<h4>\u4e8c\u3001\u9898\u76ee\u5206\u6790<\/h4>\n<h5>1. \u9898\u76ee\u8981\u6c42<\/h5>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684\u6570\u7ec4 nums&#xff0c;\u8fd4\u56de\u5176\u4e2d\u7684\u591a\u6570\u5143\u7d20\u3002<\/p>\n<p>\u591a\u6570\u5143\u7d20\u662f\u6307\u5728\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u5927\u4e8e \u230an \/ 2\u230b \u7684\u5143\u7d20\u3002\u53ef\u4ee5\u5047\u8bbe\u6570\u7ec4\u662f\u975e\u7a7a\u7684&#xff0c;\u5e76\u4e14\u7ed9\u5b9a\u7684\u6570\u7ec4\u603b\u662f\u5b58\u5728\u591a\u6570\u5143\u7d20\u3002<\/p>\n<p>\u793a\u4f8b 1&#xff1a;nums &#061; [3, 2, 3] \u2192 3<\/p>\n<p>\u793a\u4f8b 2&#xff1a;nums &#061; [2, 2, 1, 1, 1, 2, 2] \u2192 2<\/p>\n<h5>2. \u600e\u4e48\u60f3\u8fd9\u9898&#xff1f;<\/h5>\n<p>\u9898\u76ee\u8981\u627e\u4e00\u4e2a\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5143\u7d20&#xff0c;\u800c\u4e14\u5b83\u6709\u4e2a\u5f88\u5f3a\u7684\u4fdd\u8bc1&#xff1a;\u6b21\u6570\u8d85\u8fc7 n\/2&#xff08;\u4e00\u534a\u4ee5\u4e0a&#xff09;\u3002<\/p>\n<p>\u8fd9\u4e2a&#034;\u8d85\u8fc7\u4e00\u534a&#034;\u662f\u6574\u4e2a\u9898\u7684\u9898\u773c&#xff0c;\u56f4\u7ed5\u5b83\u80fd\u60f3\u51fa\u4e09\u79cd\u5c42\u6b21\u7684\u89e3\u6cd5&#xff1a;<\/p>\n<ul>\n<li>\u8001\u8001\u5b9e\u5b9e\u6570&#xff1a;\u7528\u54c8\u5e0c\u8868\u628a\u6bcf\u4e2a\u6570\u51fa\u73b0\u51e0\u6b21\u7edf\u8ba1\u51fa\u6765&#xff0c;\u8c01\u8d85\u8fc7 n\/2 \u5c31\u8fd4\u56de\u8c01\u3002\u76f4\u89c2&#xff0c;\u4f46\u8981\u591a\u82b1 O(n) \u7684\u7a7a\u95f4\u3002<\/li>\n<li>\u5229\u7528&#034;\u8d85\u8fc7\u4e00\u534a&#034;\u8fd9\u4e2a\u4f4d\u7f6e\u6027\u8d28&#xff1a;\u65e2\u7136\u5b83\u5360\u4e86\u4e00\u534a\u4ee5\u4e0a&#xff0c;\u628a\u5b83\u6392\u597d\u5e8f\u4e4b\u540e&#xff0c;\u6570\u7ec4\u6b63\u4e2d\u95f4\u90a3\u4e2a\u4f4d\u7f6e\u662f\u4e0d\u662f\u4e00\u5b9a\u5c31\u662f\u5b83&#xff1f;\u987a\u7740\u8fd9\u4e2a\u60f3\u6cd5\u80fd\u7701\u6389\u54c8\u5e0c\u8868\u3002<\/li>\n<li>\u518d\u5f80\u6df1\u60f3\u4e00\u5c42&#xff1a;\u8fc7\u534a\u610f\u5473\u7740\u5b83\u6bd4\u5176\u4ed6\u6240\u6709\u5143\u7d20\u7684\u603b\u6570\u8fd8\u591a\u3002\u5982\u679c\u8ba9\u5143\u7d20&#034;\u4e24\u4e24\u62b5\u6d88&#034;&#xff0c;\u5b83\u662f\u4e0d\u662f\u6ce8\u5b9a\u62b5\u6d88\u4e0d\u5b8c\u3001\u6700\u540e\u5269\u4e0b\u6765&#xff1f;\u8fd9\u5c31\u662f\u6469\u5c14\u6295\u7968\u6cd5&#xff0c;\u80fd\u505a\u5230 O(n) \u65f6\u95f4\u3001O(1) \u7a7a\u95f4\u3002<\/li>\n<\/ul>\n<h5>3. \u9700\u8981\u89e3\u51b3\u54ea\u51e0\u4e2a\u95ee\u9898&#xff1f;<\/h5>\n<p>\u95ee\u9898\u4e00&#xff1a;\u54c8\u5e0c\u8868\u8ba1\u6570\u600e\u4e48\u5b9e\u73b0&#xff1f;\u4e3a\u4ec0\u4e48\u5b83\u62ff\u4e0d\u5230&#034;O(1) \u7a7a\u95f4&#034;&#xff1f;<\/p>\n<p>\u95ee\u9898\u4e8c&#xff1a;\u4e3a\u4ec0\u4e48\u6392\u5e8f\u4e4b\u540e&#xff0c;\u4e0b\u6807 n\/2 \u7684\u4f4d\u7f6e\u4e00\u5b9a\u662f\u591a\u6570\u5143\u7d20&#xff1f;\u600e\u4e48\u8bc1\u660e&#xff1f;<\/p>\n<p>\u95ee\u9898\u4e09&#xff08;\u6838\u5fc3&#xff09;&#xff1a;\u6469\u5c14\u6295\u7968\u6cd5\u91cc\u90a3\u4e2a&#034;\u62b5\u6d88&#034;\u5230\u5e95\u5728\u5e72\u4ec0\u4e48&#xff1f;\u4e3a\u4ec0\u4e48\u591a\u6570\u5143\u7d20\u62b5\u6d88\u5230\u6700\u540e\u4e00\u5b9a\u5269\u5f97\u4e0b&#xff1f;<\/p>\n<hr \/>\n<h4>\u4e09\u3001\u65b9\u6cd5\u4e00&#xff1a;\u54c8\u5e0c\u8868\u8ba1\u6570&#xff0c;O(n) \u7a7a\u95f4<\/h4>\n<h5>1. \u601d\u8def\u6982\u89c8<\/h5>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">int<\/span> <span class=\"token function\">majorityElement<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> nums<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">Map<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">Integer<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Integer<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> count <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">HashMap<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> n <span class=\"token operator\">&#061;<\/span> nums<span class=\"token punctuation\">.<\/span>length<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> num <span class=\"token operator\">:<\/span> nums<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">int<\/span> c <span class=\"token operator\">&#061;<\/span> count<span class=\"token punctuation\">.<\/span><span class=\"token function\">getOrDefault<\/span><span class=\"token punctuation\">(<\/span>num<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        count<span class=\"token punctuation\">.<\/span><span class=\"token function\">put<\/span><span class=\"token punctuation\">(<\/span>num<span class=\"token punctuation\">,<\/span> c<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>c <span class=\"token operator\">&gt;<\/span> n <span class=\"token operator\">\/<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> num<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u5df2\u7ecf\u8d85\u8fc7\u4e00\u534a&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u8fd4\u56de<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u601d\u8def\u7b80\u8981\u8bf4\u660e&#xff1a;<\/p>\n<li>\u8fb9\u626b\u8fb9\u8ba1\u6570&#xff1a;map \u91cc\u5b58&#034;\u8fd9\u4e2a\u6570\u51fa\u73b0\u4e86\u51e0\u6b21&#034;<\/li>\n<li>\u968f\u65f6\u68c0\u67e5&#xff1a;\u6bcf\u52a0\u4e00\u6b21\u5c31\u770b\u770b\u6b21\u6570\u6709\u6ca1\u6709\u8d85\u8fc7 n \/ 2&#xff0c;\u8d85\u8fc7\u5c31\u662f\u7b54\u6848<\/li>\n<li>\u65f6\u95f4\u590d\u6742\u5ea6 O(n)&#xff0c;\u7a7a\u95f4 O(n)<\/li>\n<h5>2. \u601d\u8def\u8be6\u89e3<\/h5>\n<p>count.getOrDefault(num, 0) \u7684\u610f\u601d\u662f&#034;\u53d6\u51fa num \u5f53\u524d\u7684\u8ba1\u6570&#xff0c;\u5982\u679c\u6ca1\u6709\u5c31\u5f53 0&#034;&#xff0c;\u52a0 1 \u4e4b\u540e\u518d\u5199\u56de map\u3002\u6bcf\u5199\u56de\u4e00\u6b21\u5c31\u5224\u65ad\u4e00\u4e0b\u6709\u6ca1\u6709\u8fc7\u534a\u3002<\/p>\n<p>\u4ee5 [2, 2, 1, 1, 1, 2, 2]&#xff08;n &#061; 7&#xff0c;\u4e00\u534a\u662f 3&#xff09;\u4e3a\u4f8b&#xff1a;<\/p>\n<p>num&#061;2&#xff1a;\u8ba1\u6570 2\u21921<br \/>\nnum&#061;2&#xff1a;\u8ba1\u6570 2\u21922<br \/>\nnum&#061;1&#xff1a;\u8ba1\u6570 1\u21921<br \/>\nnum&#061;1&#xff1a;\u8ba1\u6570 1\u21922<br \/>\nnum&#061;1&#xff1a;\u8ba1\u6570 1\u21923<br \/>\nnum&#061;2&#xff1a;\u8ba1\u6570 2\u21923<br \/>\nnum&#061;2&#xff1a;\u8ba1\u6570 2\u21924  &gt; 3 \u2192 \u8fd4\u56de 2 \u2713<\/p>\n<p>\u601d\u8def\u6ca1\u6709\u7ed5\u5f2f&#xff0c;\u552f\u4e00\u7684\u95ee\u9898\u662f\u90a3\u4e2a\u54c8\u5e0c\u8868\u2014\u2014\u6700\u574f\u60c5\u51b5\u4e0b\u8981\u5b58\u4e0b\u6240\u6709\u4e0d\u540c\u7684\u6570&#xff0c;\u7a7a\u95f4\u662f O(n)\u3002\u9898\u76ee\u6ca1\u5f3a\u5236\u8981\u6c42\u7701\u7a7a\u95f4&#xff0c;\u4f46\u65e2\u7136&#034;\u8d85\u8fc7\u4e00\u534a&#034;\u8fd9\u4e2a\u6761\u4ef6\u8fd8\u80fd\u5229\u7528&#xff0c;\u5c31\u503c\u5f97\u5f80\u4e0b\u60f3\u3002<\/p>\n<h5>3. \u590d\u6742\u5ea6\u5206\u6790<\/h5>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6 O(n)&#xff1a;\u904d\u5386\u4e00\u6b21&#xff0c;\u54c8\u5e0c\u64cd\u4f5c\u5747\u644a O(1)\u3002<\/p>\n<p>\u7a7a\u95f4\u590d\u6742\u5ea6 O(n)&#xff1a;\u54c8\u5e0c\u8868\u6700\u591a\u5b58 n \u4e2a\u4e0d\u540c\u7684\u952e\u3002<\/p>\n<hr \/>\n<h4>\u56db\u3001\u65b9\u6cd5\u4e8c&#xff1a;\u6392\u5e8f\u540e\u53d6\u4e2d\u95f4&#xff0c;O(n log n)<\/h4>\n<h5>1. \u601d\u8def\u6982\u89c8<\/h5>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">int<\/span> <span class=\"token function\">majorityElement<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> nums<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">Arrays<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">sort<\/span><span class=\"token punctuation\">(<\/span>nums<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> nums<span class=\"token punctuation\">[<\/span>nums<span class=\"token punctuation\">.<\/span>length <span class=\"token operator\">\/<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u601d\u8def\u7b80\u8981\u8bf4\u660e&#xff1a;<\/p>\n<li>\u5148\u6392\u5e8f&#xff1a;\u76f8\u540c\u7684\u5143\u7d20\u4f1a\u88ab\u6392\u5230\u4e00\u8d77<\/li>\n<li>\u76f4\u63a5\u53d6\u4e2d\u95f4&#xff1a;\u4e0b\u6807 n \/ 2 \u4e0a\u7684\u5143\u7d20\u5c31\u662f\u591a\u6570\u5143\u7d20<\/li>\n<li>\u65f6\u95f4\u590d\u6742\u5ea6 O(n log n)&#xff0c;\u7a7a\u95f4 O(1)&#xff08;\u4e0d\u7b97\u6392\u5e8f\u672c\u8eab\u7684\u5f00\u9500&#xff09;<\/li>\n<h5>2. \u601d\u8def\u8be6\u89e3<\/h5>\n<p>\u4e3a\u4ec0\u4e48\u4e2d\u95f4\u90a3\u4e2a\u4f4d\u7f6e\u4e00\u5b9a\u662f\u591a\u6570\u5143\u7d20&#xff1f;<\/p>\n<p>\u8bbe\u591a\u6570\u5143\u7d20\u4e3a m&#xff0c;\u5b83\u51fa\u73b0\u4e86 c \u6b21&#xff0c;\u9898\u76ee\u4fdd\u8bc1 c &gt; n \/ 2&#xff0c;\u4e5f\u5c31\u662f c \u2265 \u230an\/2\u230b &#043; 1\u3002<\/p>\n<p>\u6392\u597d\u5e8f\u4e4b\u540e&#xff0c;\u6240\u6709\u7b49\u4e8e m \u7684\u5143\u7d20\u4f1a\u8fde\u6210\u4e00\u6574\u5757&#xff0c;\u5360\u636e\u4e00\u6bb5\u8fde\u7eed\u7684\u4f4d\u7f6e\u3002\u7528\u53cd\u8bc1\u6cd5&#xff1a;\u5047\u8bbe\u4e0b\u6807 n\/2 \u90a3\u4e2a\u4f4d\u7f6e\u4e0a\u4e0d\u662f m&#xff0c;\u90a3\u8bf4\u660e m \u90a3\u4e00\u6574\u5757\u8981\u4e48\u6574\u4e2a\u5728\u5b83\u5de6\u8fb9\u3001\u8981\u4e48\u6574\u4e2a\u5728\u5b83\u53f3\u8fb9\u3002<\/p>\n<ul>\n<li>\u5982\u679c\u6574\u5757\u90fd\u5728\u4e0b\u6807 n\/2 \u7684\u5de6\u8fb9&#xff0c;\u90a3\u5b83\u6700\u591a\u53ea\u80fd\u5360\u636e\u524d \u230an\/2\u230b \u4e2a\u4f4d\u7f6e&#xff0c;\u4e5f\u5c31\u662f c \u2264 \u230an\/2\u230b&#xff0c;\u548c c \u2265 \u230an\/2\u230b &#043; 1 \u77db\u76fe&#xff1b;<\/li>\n<li>\u5982\u679c\u6574\u5757\u90fd\u5728\u53f3\u8fb9&#xff0c;\u540c\u7406\u6700\u591a\u4e5f\u53ea\u80fd\u5360 \u230an\/2\u230b \u4e2a\u4f4d\u7f6e&#xff0c;\u540c\u6837\u77db\u76fe\u3002<\/li>\n<\/ul>\n<p>\u4e24\u8fb9\u90fd\u4e0d\u53ef\u80fd&#xff0c;\u6240\u4ee5\u4e0b\u6807 n\/2 \u4e0a\u53ea\u80fd\u662f m\u3002<\/p>\n<p>\u62ff [2, 2, 1, 1, 1, 2, 2] \u770b&#xff0c;\u6392\u5e8f\u540e\u662f [1, 1, 1, 2, 2, 2, 2]&#xff0c;n &#061; 7&#xff0c;n \/ 2 &#061; 3&#xff0c;\u4e0b\u6807 3 \u4e0a\u6b63\u597d\u662f 2 \u2713\u3002<\/p>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u7684\u5de7\u5999\u4e4b\u5904\u5728\u4e8e&#xff1a;\u5b83\u538b\u6839\u4e0d\u7528\u77e5\u9053\u6bcf\u4e2a\u6570\u51fa\u73b0\u51e0\u6b21&#xff0c;\u53ea\u9760&#034;\u8fc7\u534a \u21d2 \u5fc5\u7136\u9738\u5360\u4e2d\u95f4\u4f4d\u7f6e&#034;\u8fd9\u4e00\u6761\u6027\u8d28\u5c31\u591f\u3002\u4ee3\u4ef7\u662f\u6392\u5e8f\u8981 O(n log n)&#xff0c;\u6bd4\u7ebf\u6027\u6162\u3002<\/p>\n<h5>3. \u590d\u6742\u5ea6\u5206\u6790<\/h5>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6 O(n log n)&#xff1a;\u6392\u5e8f\u5360\u4e3b\u8981\u5f00\u9500\u3002<\/p>\n<p>\u7a7a\u95f4\u590d\u6742\u5ea6 O(1)&#xff1a;\u53ea\u7528\u4e86\u4e0b\u6807\u3002<\/p>\n<hr \/>\n<h4>\u4e94\u3001\u65b9\u6cd5\u4e09&#xff1a;\u6469\u5c14\u6295\u7968\u6cd5&#xff0c;O(n) \u65f6\u95f4 &#043; O(1) \u7a7a\u95f4<\/h4>\n<h5>1. \u601d\u8def\u6982\u89c8<\/h5>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">int<\/span> <span class=\"token function\">majorityElement<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> nums<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> candidate <span class=\"token operator\">&#061;<\/span> nums<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> count <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> num <span class=\"token operator\">:<\/span> nums<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>count <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            candidate <span class=\"token operator\">&#061;<\/span> num<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u524d\u9762\u7684\u90fd\u88ab\u62b5\u6d88\u5149\u4e86&#xff0c;\u6362\u8fd9\u4e2a\u6570\u5f53\u5019\u9009\u4eba<\/span><br \/>\n            count <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>num <span class=\"token operator\">&#061;&#061;<\/span> candidate<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            count<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">;<\/span>           <span class=\"token comment\">\/\/ \u652f\u6301\u7968 &#043;1<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            count<span class=\"token operator\">&#8212;<\/span><span class=\"token punctuation\">;<\/span>           <span class=\"token comment\">\/\/ \u53cd\u5bf9\u7968&#xff0c;\u62b5\u6d88\u6389\u4e00\u5f20\u652f\u6301\u7968<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> candidate<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u601d\u8def\u7b80\u8981\u8bf4\u660e&#xff1a;<\/p>\n<li>\u7ef4\u62a4\u4e00\u4e2a\u5019\u9009\u4eba&#xff1a;candidate \u662f\u5f53\u524d&#034;\u9886\u5148&#034;\u7684\u90a3\u4e2a\u6570<\/li>\n<li>count \u662f\u5b83\u7684\u51c0\u7968\u6570&#xff1a;\u9047\u5230\u76f8\u540c\u7684\u5c31 &#043;1&#xff0c;\u9047\u5230\u4e0d\u540c\u7684\u5c31 \u22121<\/li>\n<li>\u51c0\u7968\u6570\u5f52\u96f6\u5c31\u6362\u4eba&#xff1a;\u8bf4\u660e\u5019\u9009\u4eba\u88ab\u62b5\u6d88\u5149\u4e86&#xff0c;\u8ba9\u4e0b\u4e00\u4e2a\u6570\u4e0a\u53f0<\/li>\n<li>\u6700\u540e\u5269\u4e0b\u7684\u5c31\u662f\u591a\u6570\u5143\u7d20<\/li>\n<li>\u65f6\u95f4\u590d\u6742\u5ea6 O(n)&#xff0c;\u7a7a\u95f4 O(1)<\/li>\n<h5>2. \u601d\u8def\u8be6\u89e3<\/h5>\n<p>\u7b2c\u4e00\u6b65&#xff1a;\u628a\u95ee\u9898\u770b\u6210&#034;\u4e92\u76f8\u62b5\u6d88&#034;<\/p>\n<p>\u591a\u6570\u5143\u7d20\u51fa\u73b0\u6b21\u6570\u8d85\u8fc7 n\/2&#xff0c;\u4e5f\u5c31\u662f\u8bf4&#xff1a;\u5b83\u7684\u4e2a\u6570&#xff0c;\u6bd4\u5176\u4f59\u6240\u6709\u5143\u7d20\u52a0\u8d77\u6765\u8fd8\u591a\u3002<\/p>\n<p>\u8fd9\u53e5\u8bdd\u5f88\u5bb9\u6613\u88ab\u5ffd\u7565&#xff0c;\u4f46\u5b83\u662f\u6574\u4e2a\u65b9\u6cd5\u7684\u6839\u57fa\u3002\u65e2\u7136\u5b83\u4e00\u65b9\u4eba\u9a6c\u6bd4&#034;\u5176\u4ed6\u6240\u6709\u4eba\u52a0\u8d77\u6765&#034;\u8fd8\u591a&#xff0c;\u90a3\u5c31\u8ba9\u4e0d\u540c\u9635\u8425\u7684\u5143\u7d20\u4e24\u4e24\u62b5\u6d88\u2014\u2014\u6bcf\u62b5\u6d88\u6389\u4e00\u4e2a\u591a\u6570\u5143\u7d20&#xff0c;\u4e5f\u5fc5\u7136\u8981\u642d\u4e0a\u4e00\u4e2a\u522b\u7684\u5143\u7d20\u3002\u5c31\u7b97\u628a\u5176\u4ed6\u5143\u7d20\u5168\u90e8\u62ff\u53bb\u548c\u5b83\u62fc\u6389&#xff0c;\u5b83\u4e5f\u8fd8\u5269\u5f97\u4e0b&#xff08;\u56e0\u4e3a\u5b83\u7684\u603b\u6570\u672c\u6765\u5c31\u66f4\u591a&#xff09;\u3002\u6240\u4ee5\u62b5\u6d88\u5230\u6700\u540e&#xff0c;\u573a\u4e0a\u5269\u4e0b\u7684\u53ea\u80fd\u662f\u5b83\u3002<\/p>\n<p>\u7b2c\u4e8c\u6b65&#xff1a;candidate \u548c count \u5728\u8bb0\u5f55\u4ec0\u4e48<\/p>\n<p>\u4ee3\u7801\u628a\u4e0a\u9762\u8fd9\u4e2a\u8fc7\u7a0b\u538b\u7f29\u6210\u4e86\u4e24\u4e2a\u53d8\u91cf&#xff1a;<\/p>\n<ul>\n<li>candidate&#xff1a;\u5f53\u524d\u5360\u4e0a\u98ce\u7684\u90a3\u4e2a\u5143\u7d20&#xff1b;<\/li>\n<li>count&#xff1a;\u5b83\u624b\u91cc\u8fd8\u5269\u591a\u5c11&#034;\u51c0\u7968&#034;&#xff08;\u652f\u6301\u5b83\u7684\u6570\u91cf\u51cf\u53bb\u88ab\u53cd\u5bf9\u6389\u7684&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u904d\u5386\u65f6\u7684\u4e09\u79cd\u52a8\u4f5c&#xff1a;<\/p>\n<ul>\n<li>\u9047\u5230\u548c candidate \u76f8\u540c\u7684\u6570 \u2192 \u662f\u81ea\u5df1\u4eba&#xff0c;count&#043;&#043;&#xff1b;<\/li>\n<li>\u9047\u5230\u548c candidate \u4e0d\u540c\u7684\u6570 \u2192 \u6362\u6389\u4e00\u4e2a&#xff0c;count&#8211;&#xff08;\u4e00\u7968\u652f\u6301\u88ab\u4e00\u7968\u53cd\u5bf9\u62b5\u6d88&#xff09;&#xff1b;<\/li>\n<li>count \u51cf\u5230 0 \u2192 \u8bf4\u660e\u524d\u9762\u6512\u7684\u7968\u5168\u88ab\u62b5\u6d88\u5149\u4e86&#xff0c;candidate \u5df2\u7ecf\u540d\u5b58\u5b9e\u4ea1\u3002\u8fd9\u65f6\u8ba9\u5f53\u524d\u8fd9\u4e2a\u6570\u5f53\u65b0\u5019\u9009\u4eba&#xff0c;count &#061; 1 \u91cd\u65b0\u5f00\u59cb\u3002<\/li>\n<\/ul>\n<p>\u4e3a\u4ec0\u4e48\u5f52\u96f6\u65f6\u53ef\u4ee5\u653e\u5fc3\u6362\u4eba&#xff1f; \u56e0\u4e3a count \u5f52\u96f6\u610f\u5473\u7740&#034;\u4ece\u5f00\u5934\u5230\u73b0\u5728\u8fd9\u4e00\u6bb5&#xff0c;\u652f\u6301\u7968\u548c\u53cd\u5bf9\u7968\u6b63\u597d\u6253\u6210\u5e73\u624b&#xff0c;\u6574\u6bb5\u5168\u62b5\u6d88\u4e86&#034;\u3002\u8fd9\u4e00\u6bb5\u65e2\u7136\u80fd\u81ea\u6211\u6d88\u5316\u5e72\u51c0&#xff0c;\u628a\u5b83\u6574\u4e2a\u4e22\u6389\u4e5f\u4e0d\u5f71\u54cd\u5269\u4e0b\u7684\u90e8\u5206\u2014\u2014\u540e\u9762\u90a3\u4e9b\u6570\u7684&#034;\u8c01\u66f4\u591a&#034;\u7684\u683c\u5c40&#xff0c;\u548c\u524d\u9762\u8fd9\u4e00\u6bb5\u7684\u62b5\u6d88\u7ed3\u679c\u65e0\u5173\u3002\u6240\u4ee5\u53ef\u4ee5\u653e\u5fc3\u4ece\u90a3\u4e00\u4f4d\u91cd\u65b0\u5f00\u59cb\u6570\u3002<\/p>\n<p>\u7b2c\u4e09\u6b65&#xff1a;\u5b8c\u6574\u6267\u884c\u8fc7\u7a0b<\/p>\n<p>\u4ee5 [2, 2, 1, 1, 1, 2, 2]&#xff08;\u7b54\u6848\u662f 2&#xff09;\u4e3a\u4f8b&#xff1a;<\/p>\n<p>num&#061;2&#xff1a;count&#061;0 \u2192 candidate&#061;2, count&#061;1      \u2190 2 \u4e0a\u53f0<br \/>\nnum&#061;2&#xff1a;&#061;&#061; candidate \u2192 count&#061;2                \u2190 \u53c8\u6765\u4e00\u4e2a\u81ea\u5df1\u4eba<br \/>\nnum&#061;1&#xff1a;!&#061; candidate \u2192 count&#061;1                \u2190 1 \u62b5\u6d88\u6389\u4e00\u5f20\u7968<br \/>\nnum&#061;1&#xff1a;!&#061; candidate \u2192 count&#061;0                \u2190 \u53c8\u62b5\u6d88\u4e00\u5f20&#xff0c;2 \u88ab\u62fc\u5149\u4e86<br \/>\nnum&#061;1&#xff1a;count&#061;0 \u2192 candidate&#061;1, count&#061;1        \u2190 1 \u4e0a\u53f0<br \/>\nnum&#061;2&#xff1a;!&#061; candidate \u2192 count&#061;0                \u2190 2 \u628a 1 \u62fc\u5149<br \/>\nnum&#061;2&#xff1a;count&#061;0 \u2192 candidate&#061;2, count&#061;1        \u2190 2 \u518d\u6b21\u4e0a\u53f0<br \/>\n\u8fd4\u56de candidate &#061; 2 \u2713<\/p>\n<p>\u518d\u770b\u793a\u4f8b 1 \u7684 [3, 2, 3]&#xff1a;<\/p>\n<p>num&#061;3&#xff1a;count&#061;0 \u2192 candidate&#061;3, count&#061;1<br \/>\nnum&#061;2&#xff1a;!&#061; \u2192 count&#061;0<br \/>\nnum&#061;3&#xff1a;count&#061;0 \u2192 candidate&#061;3, count&#061;1<br \/>\n\u8fd4\u56de 3 \u2713<\/p>\n<p>\u53ef\u4ee5\u7559\u610f\u5230&#xff1a;\u4e2d\u95f4 candidate \u6362\u6210\u8fc7 1&#xff0c;\u4e5f\u5f52\u96f6\u8fc7\u597d\u51e0\u6b21&#xff0c;\u4f46\u6700\u540e\u7ad9\u7740\u7684\u8fd8\u662f 2\u2014\u2014\u56e0\u4e3a\u591a\u6570\u5143\u7d20\u603b\u6570\u6700\u591a&#xff0c;\u62b5\u6d88\u5230\u6700\u540e\u5269\u4e0b\u7684\u4e00\u5b9a\u662f\u5b83\u3002\u4e2d\u95f4\u90a3\u4e9b\u8d77\u4f0f\u53ea\u662f&#034;\u8fd8\u6ca1\u5206\u51fa\u80dc\u8d1f&#034;\u7684\u4e34\u65f6\u72b6\u6001\u3002<\/p>\n<p>\u7b2c\u56db\u6b65&#xff1a;\u4ee3\u7801\u7ec6\u8282<\/p>\n<ul>\n<li>count &#061;&#061; 0 \u65f6\u7edf\u4e00\u5904\u7406&#xff1a;\u8fd9\u4e2a\u5206\u652f\u540c\u65f6\u517c\u987e\u4e86&#034;\u6570\u7ec4\u7b2c\u4e00\u4e2a\u5143\u7d20&#034;&#xff08;\u521d\u59cb count &#061; 0&#xff0c;\u7b2c\u4e00\u4e2a\u6570\u81ea\u7136\u4e0a\u53f0&#xff09;\u548c&#034;\u5019\u9009\u4eba\u88ab\u62fc\u5149\u540e\u6362\u4eba&#034;&#xff0c;\u4e0d\u7528\u7ed9\u7b2c\u4e00\u4e2a\u5143\u7d20\u5355\u72ec\u5199\u903b\u8f91\u3002<\/li>\n<li>\u6700\u540e\u4e0d\u9700\u8981\u518d\u9a8c\u8bc1&#xff1a;\u9898\u76ee\u4fdd\u8bc1\u591a\u6570\u5143\u7d20\u4e00\u5b9a\u5b58\u5728&#xff0c;\u6240\u4ee5\u5faa\u73af\u7ed3\u675f\u65f6 candidate \u5fc5\u7136\u662f\u7b54\u6848\u3002\u5982\u679c\u9898\u76ee\u4e0d\u4fdd\u8bc1&#xff0c;\u5c31\u5f97\u518d\u626b\u4e00\u904d\u6570\u7ec4\u786e\u8ba4\u5b83\u771f\u7684\u8fc7\u534a\u3002<\/li>\n<li>count \u7684\u542b\u4e49\u8981\u8bb0\u51c6&#xff1a;\u5b83\u4e0d\u662f&#034;\u5019\u9009\u4eba\u51fa\u73b0\u7684\u603b\u6b21\u6570&#034;&#xff0c;\u800c\u662f&#034;\u51c0\u7968\u6570&#034;&#xff0c;\u4e2d\u9014\u88ab\u62b5\u6d88\u6389\u7684\u7968\u5df2\u7ecf\u4ece\u91cc\u9762\u6263\u6389\u4e86\u3002<\/li>\n<\/ul>\n<h5>3. \u590d\u6742\u5ea6\u5206\u6790<\/h5>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6 O(n)&#xff1a;\u4e00\u6b21\u904d\u5386&#xff0c;\u6bcf\u4e2a\u5143\u7d20\u5e38\u6570\u6b21\u6bd4\u8f83\u3002<\/p>\n<p>\u7a7a\u95f4\u590d\u6742\u5ea6 O(1)&#xff1a;\u53ea\u6709 candidate \u548c count \u4e24\u4e2a\u53d8\u91cf\u3002<\/p>\n<hr \/>\n<h4>\u516d\u3001\u603b\u7ed3<\/h4>\n<table>\n<tr>\u65b9\u6cd5\u65f6\u95f4\u7a7a\u95f4\u5173\u952e\u70b9<\/tr>\n<tbody>\n<tr>\n<td>\u54c8\u5e0c\u8868\u8ba1\u6570<\/td>\n<td>O(n)<\/td>\n<td>O(n)<\/td>\n<td>\u76f4\u63a5\u7edf\u8ba1\u6bcf\u4e2a\u6570\u7684\u51fa\u73b0\u6b21\u6570<\/td>\n<\/tr>\n<tr>\n<td>\u6392\u5e8f\u53d6\u4e2d\u95f4<\/td>\n<td>O(n log n)<\/td>\n<td>O(1)<\/td>\n<td>\u8fc7\u534a \u21d2 \u5fc5\u7136\u5360\u636e\u4e0b\u6807 n\/2<\/td>\n<\/tr>\n<tr>\n<td>\u6469\u5c14\u6295\u7968\u6cd5<\/td>\n<td>O(n)<\/td>\n<td>O(1)<\/td>\n<td>\u8fc7\u534a \u21d2 \u62b5\u6d88\u4e0d\u5b8c&#xff0c;\u6700\u540e\u5269\u7684\u5fc5\u662f\u5b83<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e09\u79cd\u65b9\u6cd5\u4e00\u5c42\u6bd4\u4e00\u5c42\u7701&#xff0c;\u5171\u540c\u7684\u57fa\u7840\u90fd\u662f\u9898\u76ee\u90a3\u53e5&#034;\u51fa\u73b0\u6b21\u6570\u5927\u4e8e \u230an\/2\u230b&#034;&#xff1a;<\/p>\n<ul>\n<li>\u8001\u8001\u5b9e\u5b9e\u8ba1\u6570&#xff0c;\u662f\u628a&#034;\u8fc7\u534a&#034;\u4ea4\u7ed9\u54c8\u5e0c\u8868\u53bb\u5224\u65ad&#xff1b;<\/li>\n<li>\u6392\u5e8f\u53d6\u4e2d\u95f4&#xff0c;\u662f\u628a&#034;\u8fc7\u534a&#034;\u7ffb\u8bd1\u6210&#034;\u4f4d\u7f6e\u6027\u8d28&#034;\u2014\u2014\u5b83\u5fc5\u7136\u9738\u5360\u6b63\u4e2d\u95f4&#xff1b;<\/li>\n<li>\u6469\u5c14\u6295\u7968&#xff0c;\u662f\u628a&#034;\u8fc7\u534a&#034;\u7ffb\u8bd1\u6210&#034;\u6570\u91cf\u5bf9\u6bd4&#034;\u2014\u2014\u5b83\u6bd4\u5176\u4f59\u6240\u6709\u5143\u7d20\u52a0\u8d77\u6765\u8fd8\u591a&#xff0c;\u6240\u4ee5\u4e24\u4e24\u62b5\u6d88\u4e4b\u540e\u5b83\u4e00\u5b9a\u8fd8\u5728\u3002<\/li>\n<\/ul>\n<p>\u9762\u8bd5\u91cc\u6700\u5e38\u88ab\u8ffd\u95ee\u7684\u662f\u6469\u5c14\u6295\u7968\u6cd5&#xff0c;\u91cd\u70b9\u4e0d\u5728\u4ee3\u7801&#xff08;\u5c31\u90a3\u4e48\u51e0\u884c&#xff09;&#xff0c;\u800c\u5728\u4e8e\u80fd\u4e0d\u80fd\u8bf4\u6e05&#034;\u4e3a\u4ec0\u4e48\u62b5\u6d88\u5230\u6700\u540e\u5269\u4e0b\u7684\u5c31\u662f\u591a\u6570\u5143\u7d20&#034;\u8fd9\u4e00\u70b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u6982\u89c8&#xff1a;\u672c\u6587\u8bb2\u89e3\u591a\u6570\u5143\u7d20&#xff1a;\u591a\u6570\u5143\u7d20\u51fa\u73b0\u6b21\u6570\u8d85\u8fc7 n\/2&#xff0c;\u6240\u4ee5\u6392\u5e8f\u540e\u4e0b\u6807 n\/2 \u7684\u4f4d\u7f6e\u4e00\u5b9a\u662f\u5b83&#xff1b;\u66f4\u4f18\u7684\u6469\u5c14\u6295\u7968\u6cd5\u628a\u95ee\u9898\u770b\u6210\\&#8221;\u4e24\u4e24\u62b5\u6d88\\&#8221;&#xff0c;\u56e0\u4e3a\u591a\u6570\u5143\u7d20\u7684\u603b\u6570\u8d85\u8fc7\u5176\u4f59\u5143\u7d20\u4e4b\u548c&#xff0c;\u62b5\u6d88\u5230\u6700\u540e\u5269\u4e0b\u7684\u5c31\u662f\u5b83&#xff0c;O(n) \u65f6\u95f4\u3001O(1) \u7a7a\u95f4\u4e00\u3001\u9898\u76ee\u4e8c\u3001\u9898\u76ee\u5206\u6790<br \/>\n1. \u9898\u76ee\u8981\u6c42<br \/>\n\u7ed9\u5b9a\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684\u6570\u7ec4 nums&#xff0c;\u8fd4\u56de\u5176\u4e2d\u7684\u591a\u6570\u5143\u7d20\u3002<br \/>\n\u591a\u6570\u5143\u7d20\u662f\u6307\u5728\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u5927\u4e8e \u230an \/<\/p>\n","protected":false},"author":2,"featured_media":110360,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,2692,1813,427],"topic":[],"class_list":["post-110361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-leetcode","tag-1813","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Hot 100 - \u591a\u6570\u5143\u7d20 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/110361.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hot 100 - \u591a\u6570\u5143\u7d20 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u672c\u6587\u6982\u89c8&#xff1a;\u672c\u6587\u8bb2\u89e3\u591a\u6570\u5143\u7d20&#xff1a;\u591a\u6570\u5143\u7d20\u51fa\u73b0\u6b21\u6570\u8d85\u8fc7 n\/2&#xff0c;\u6240\u4ee5\u6392\u5e8f\u540e\u4e0b\u6807 n\/2 \u7684\u4f4d\u7f6e\u4e00\u5b9a\u662f\u5b83&#xff1b;\u66f4\u4f18\u7684\u6469\u5c14\u6295\u7968\u6cd5\u628a\u95ee\u9898\u770b\u6210&quot;\u4e24\u4e24\u62b5\u6d88&quot;&#xff0c;\u56e0\u4e3a\u591a\u6570\u5143\u7d20\u7684\u603b\u6570\u8d85\u8fc7\u5176\u4f59\u5143\u7d20\u4e4b\u548c&#xff0c;\u62b5\u6d88\u5230\u6700\u540e\u5269\u4e0b\u7684\u5c31\u662f\u5b83&#xff0c;O(n) \u65f6\u95f4\u3001O(1) \u7a7a\u95f4\u4e00\u3001\u9898\u76ee\u4e8c\u3001\u9898\u76ee\u5206\u6790 1. \u9898\u76ee\u8981\u6c42 \u7ed9\u5b9a\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684\u6570\u7ec4 nums&#xff0c;\u8fd4\u56de\u5176\u4e2d\u7684\u591a\u6570\u5143\u7d20\u3002 \u591a\u6570\u5143\u7d20\u662f\u6307\u5728\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u5927\u4e8e \u230an \/\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/110361.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-26T11:09:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260926110911-6ab7a7d71bea4.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/110361.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/110361.html\",\"name\":\"Hot 100 - \u591a\u6570\u5143\u7d20 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-26T11:09:13+00:00\",\"dateModified\":\"2026-09-26T11:09:13+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/110361.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/110361.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/110361.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hot 100 --- \u591a\u6570\u5143\u7d20\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hot 100 - \u591a\u6570\u5143\u7d20 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/110361.html","og_locale":"zh_CN","og_type":"article","og_title":"Hot 100 - \u591a\u6570\u5143\u7d20 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u672c\u6587\u6982\u89c8&#xff1a;\u672c\u6587\u8bb2\u89e3\u591a\u6570\u5143\u7d20&#xff1a;\u591a\u6570\u5143\u7d20\u51fa\u73b0\u6b21\u6570\u8d85\u8fc7 n\/2&#xff0c;\u6240\u4ee5\u6392\u5e8f\u540e\u4e0b\u6807 n\/2 \u7684\u4f4d\u7f6e\u4e00\u5b9a\u662f\u5b83&#xff1b;\u66f4\u4f18\u7684\u6469\u5c14\u6295\u7968\u6cd5\u628a\u95ee\u9898\u770b\u6210\"\u4e24\u4e24\u62b5\u6d88\"&#xff0c;\u56e0\u4e3a\u591a\u6570\u5143\u7d20\u7684\u603b\u6570\u8d85\u8fc7\u5176\u4f59\u5143\u7d20\u4e4b\u548c&#xff0c;\u62b5\u6d88\u5230\u6700\u540e\u5269\u4e0b\u7684\u5c31\u662f\u5b83&#xff0c;O(n) \u65f6\u95f4\u3001O(1) \u7a7a\u95f4\u4e00\u3001\u9898\u76ee\u4e8c\u3001\u9898\u76ee\u5206\u6790 1. \u9898\u76ee\u8981\u6c42 \u7ed9\u5b9a\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684\u6570\u7ec4 nums&#xff0c;\u8fd4\u56de\u5176\u4e2d\u7684\u591a\u6570\u5143\u7d20\u3002 \u591a\u6570\u5143\u7d20\u662f\u6307\u5728\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u5927\u4e8e \u230an \/","og_url":"https:\/\/www.wsisp.com\/helps\/110361.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-26T11:09:13+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260926110911-6ab7a7d71bea4.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/110361.html","url":"https:\/\/www.wsisp.com\/helps\/110361.html","name":"Hot 100 - \u591a\u6570\u5143\u7d20 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-26T11:09:13+00:00","dateModified":"2026-09-26T11:09:13+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/110361.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/110361.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/110361.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Hot 100 --- \u591a\u6570\u5143\u7d20"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/110361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=110361"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/110361\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/110360"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=110361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=110361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=110361"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=110361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}