{"id":443604,"date":"2021-04-19T12:02:45","date_gmt":"2021-04-19T04:02:45","guid":{"rendered":"http:\/\/4563.org\/?p=443604"},"modified":"2021-04-19T12:02:45","modified_gmt":"2021-04-19T04:02:45","slug":"%e5%81%9a%e5%ae%8c%e8%bf%99%e9%a2%98%e6%88%91%e5%b0%b1%e6%85%8c%e4%ba%86%ef%bc%8c%e6%80%8e%e4%b9%88%e4%bc%9a%e6%9c%89%e8%bf%99%e6%a0%b7%e7%9a%84%e9%a2%98%e7%9b%ae","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=443604","title":{"rendered":"\u505a\u5b8c\u8fd9\u9898\u6211\u5c31\u614c\u4e86\uff0c\u600e\u4e48\u4f1a\u6709\u8fd9\u6837\u7684\u9898\u76ee"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u505a\u5b8c\u8fd9\u9898\u6211\u5c31\u614c\u4e86\uff0c\u600e\u4e48\u4f1a\u6709\u8fd9\u6837\u7684\u9898\u76ee               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzzrf <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h2><strong>\u539f\u9898\u76ee\u7684\u5730\u5740\u5728\u8fd9\u91cc\uff0c\u5927\u4f6c\u4eec\u53ef\u4ee5\u770b\u770b\u6709\u6ca1\u6709\u66f4\u4f18\u7684\u89e3\u6cd5<\/strong><\/h2>\n<p>\u505a\u51fa\u6765\u89c9\u5f97\u548c K \u6ca1\u5565\u5173\u7cfb\u554a\uff0c\u5fc3\u614c\u7684\u4e00\u6279\u2026<\/p>\n<h3>\u9644\u4e0a\u6211\u7684\u89e3\u6cd5\uff1a<\/h3>\n<h2>\u7b97\u6cd5\uff1ahashmap<\/h2>\n<p>\u5f53\u4e00\u4e2a\u6570\u7684\u51fa\u73b0\u6b21\u6570\u5927\u4e8e\u7b49\u4e8e\u5143\u7d20\u603b\u6570\u9664\u4ee5 k \u5411\u4e0a\u53d6\u6574\u65f6\u8bf4\u660e\u627e\u5230\u7b54\u6848 \u5c06\u6240\u6709\u6570\u5b57\u90fd\u7528 map \u5b58\u4e0b\u6765\uff0c\u5e76\u5b58\u4e0b\u51fa\u73b0\u6b21\u6570 \u904d\u5386\u8fd9\u4e2a map\uff0c\u627e\u5230\u6b21\u6570\u5927\u4e8e\u603b\u6570 k \u5206\u4e4b\u4e00\u7684\u5143\u7d20<\/p>\n<h3>\u590d\u6742\u5ea6\u5206\u6790<\/h3>\n<ul>\n<li> \u65f6\u95f4\u590d\u6742\u5ea6 O(n)\n<ul>\n<li>n \u4e3a\u6570\u7ec4\u5927\u5c0f<\/li>\n<\/ul>\n<\/li>\n<li> \u7a7a\u95f4\u590d\u6742\u5ea6 O(n)\n<ul>\n<li>n \u4e3a\u6570\u7ec4\u5927\u5c0f<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u4ee3\u7801<\/h2>\n<pre><code>  public class Solution {     \/*      * @param nums: a list of integers      * @return: The majority number that occurs more than 1\/3      *\/     public int majorityNumber(List&lt;Integer&gt; nums, int k) {         HashMap&lt;Integer,Integer&gt; map = new HashMap&lt;&gt;();         int n = nums.size();         if(n == 0){             return -1;         }         int count = n\/k + 1;         \/\/\u904d\u5386 nums         Iterator it = nums.iterator();         while(it.hasNext()){             Integer tmp = (Integer)it.next();             if(map.containsKey(tmp)){                 int m = (int)map.get(tmp) + 1;                 map.put(tmp, m);                 \/\/ \u5224\u65ad\u662f\u5426\u5927\u4e8e\u7b49\u4e8e k \u5206\u4e4b\u4e00                 if(m &gt;= count){                     return tmp;                 }             }             else{                 map.put(tmp, 1);             }         }         return nums.get(0);     } } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5640986\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Nillouise <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9 oj \u6ca1\u7b54\u6848\u7ed9\u4f60\u770b\u5417\uff1f\u8fd9\u9898\u76ee\u5e94\u8be5\u662f\u6392\u5e8f\u7136\u540e\u904d\u5386\u4e00\u904d\uff0c\u904d\u5386\u8fc7\u7a0b\u4e2d\u8bb0\u5f55\u539a\u5ea6\u89e3\u51b3\uff0c\u4e0d\u9700\u8981\u4ec0\u4e48 hashMap                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5640987\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : zzzrf <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Nillouise \u611f\u8c22\u5927\u4f6c\uff01\u6211\u8fd8\u6ca1\u8d44\u683c\u67e5\u770b\u7b54\u6848\u2026[\u56e7]                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5640988\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Nillouise <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u53ef\u80fd\u53d1\u9519\u9898\u76ee\u4e86\uff0c\u8fde\u63a5\u7684\u9898\u76ee\u662f\u63d2\u5165\u533a\u95f4\uff0c\u8ddf\u4f60\u7684\u63cf\u8ff0\u5e94\u8be5\u6ca1\u4ec0\u4e48\u5173\u7cfb                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u505a\u5b8c\u8fd9\u9898\u6211\u5c31\u614c\u4e86\uff0c\u600e\u4e48\u4f1a\u6709\u8fd9\u6837\u7684\u9898&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/443604"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=443604"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/443604\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=443604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=443604"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=443604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}