{"id":426585,"date":"2021-04-08T15:05:25","date_gmt":"2021-04-08T07:05:25","guid":{"rendered":"http:\/\/4563.org\/?p=426585"},"modified":"2021-04-08T15:05:25","modified_gmt":"2021-04-08T07:05:25","slug":"%e4%b8%8d%e7%9f%a5%e9%81%93%e6%9c%89%e6%b2%a1%e6%9c%89%e6%9b%b4%e5%a5%bd%e7%9a%84%e5%86%99%e6%b3%95","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=426585","title":{"rendered":"\u4e0d\u77e5\u9053\u6709\u6ca1\u6709\u66f4\u597d\u7684\u5199\u6cd5"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4e0d\u77e5\u9053\u6709\u6ca1\u6709\u66f4\u597d\u7684\u5199\u6cd5               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : LowBi <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>RT.\u4e2a\u4eba\u9879\u76ee\u4e0a\u7684\u4e00\u4e2a\u95ee\u9898\uff0c\u5199\u4e86\u4e2a\u4f8b\u5b50\uff0c\u81ea\u5df1\u611f\u89c9\u5199\u7684\u65b9\u6cd5\u8f83\u7b28\u3002      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>8<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5723656\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : javapythongo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u8fd9\u4e2a\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f O(m*n)\u4e86\uff0c\u800c\u4e14\u5728 if(x[i] == y[j])\u5224\u5b9a\u76f8\u7b49\u8d4b\u503c\u540e\uff0c\u5e94\u8be5\u76f4\u63a5 break \u3002<br \/>\u53ef\u4ee5\u5148\u904d\u5386 y \u6570\u7ec4\uff0c\u5b58\u50a8\u5728\u4e00\u4e2a set \u96c6\u5408\u4e2d\uff0c\u518d\u904d\u5386 x \u6570\u7ec4\uff0c\u539f\u5730\u4fee\u6539\u5373\u53ef\uff0c\u8fd9\u6837\u5b50\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f O(m+n)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5723657\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : LGA1150 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             int[] x = {1,2,3,4,5,6,7};<br \/>int[] y = {2,4,7};<br \/>int[] z = Arrays.stream(x).map(e -&gt; Arrays.binarySearch(y, e) &lt; 0 ? 0 : e).toArray();<br \/>System.out.println(Arrays.toString(z));<br \/>\u9700\u8981\u4fdd\u8bc1 y \u6709\u5e8f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5723658\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : LGA1150 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u50cf #1 \u8bf4\u7684\u4f7f\u7528\u96c6\u5408\u5e76\u539f\u5730\u4fee\u6539\uff1a<br \/>Set&lt;Integer&gt; set = Arrays.stream(y).boxed().collect(Collectors.toSet());<br \/>for (int i = 0; i &lt; x.length; i++) {<br \/> if (!set.contains(x[i])) x[i]=0;<br \/>}<br \/>\u4e0d\u7528\u4fdd\u8bc1 y \u6709\u5e8f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5723659\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zjp <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u5047\u8bbe\u6570\u7ec4\u6709\u5e8f\u548c\u4e0d\u91cd\u590d\u7684\u60c5\u51b5<br \/> int[] x = {1, 2, 3, 4, 5, 6, 7};<br \/> int[] y = {2, 4, 7};<br \/> Map&lt;Integer, Long&gt; count = Arrays.stream(y).boxed()<br \/> .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));<br \/> int[] z = Arrays.stream(x).boxed()<br \/> .map(e -&gt; count.containsKey(e) &amp;&amp; count.put(e, count.get(e) &#8211; 1) &gt; 0 ? e : 0)<br \/> .mapToInt(Integer::intValue).toArray();<br \/> System.out.println(&#8220;z = &#8221; + Arrays.toString(z));                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5723660\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zjp <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zjp \u5bf9 IntStream \u4e0d\u719f\u6089\uff0cboxed \u7136\u540e mapToInt \u662f\u591a\u4f59\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5723661\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : LowBi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @javapythongo @LGA1150 @zjp \u611f\u8c22\u5927\u4f6c\u4eec\u63d0\u4f9b\u4ee3\u7801\u601d\u8def                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5723662\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u8fd9\u5224\u65ad a!=0 \u518d add \u8ddf\u76f4\u63a5 z.add(a) \u6709\u4ec0\u4e48\u533a\u522b\uff08<\/p>\n<p>@LGA1150 \u4f60\u8fd9\u6709\u5e8f\u662f O(m log n)\uff0cm,n&gt;4 \u7684\u8bdd\u8fd8\u4e0d\u5982\u96c6\u5408\u5462\u2026\u2026<br \/>\u6709\u5e8f\u7684\u60c5\u51b5\u4e0b\u6700\u4f18\u5e94\u662f\u4eff\u5f52\u5e76\u6392\u5e8f\u7684\u53cc\u6307\u9488\u79fb\u52a8                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5723663\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : youhuo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6765\u5b66\u4e60 \u5b66\u4e60                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0d\u77e5\u9053\u6709\u6ca1\u6709\u66f4\u597d\u7684\u5199\u6cd5 \u8cc7\u6df1\u5927\u4f6c &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\/426585"}],"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=426585"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/426585\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=426585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=426585"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=426585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}