{"id":183985,"date":"2020-10-28T21:00:24","date_gmt":"2020-10-28T13:00:24","guid":{"rendered":"http:\/\/4563.org\/?p=183985"},"modified":"2020-10-28T21:00:24","modified_gmt":"2020-10-28T13:00:24","slug":"google-%e9%9d%a2%e8%af%95%e9%a2%98%ef%bc%9a%e6%95%b0%e6%8d%ae%e6%b5%81%e6%bb%91%e5%8a%a8%e7%aa%97%e5%8f%a3%e5%b9%b3%e5%9d%87%e5%80%bc","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=183985","title":{"rendered":"Google \u9762\u8bd5\u9898\uff1a\u6570\u636e\u6d41\u6ed1\u52a8\u7a97\u53e3\u5e73\u5747\u503c"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Google \u9762\u8bd5\u9898\uff1a\u6570\u636e\u6d41\u6ed1\u52a8\u7a97\u53e3\u5e73\u5747\u503c               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzzrf <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u7ed9\u51fa\u4e00\u4e32\u6574\u6570\u6d41\u548c\u7a97\u53e3\u5927\u5c0f\uff0c\u8ba1\u7b97\u6ed1\u52a8\u7a97\u53e3\u4e2d\u6240\u6709\u6574\u6570\u7684\u5e73\u5747\u503c\u3002<\/p>\n<p>\u5728\u7ebf\u505a\u9898\u5730\u5740<\/p>\n<h2>\u6837\u4f8b 1 :<\/h2>\n<pre><code>MovingAverage m = new MovingAverage(3); m.next(1) = 1 \/\/ \u8fd4\u56de 1.00000 m.next(10) = (1 + 10) \/ 2 \/\/ \u8fd4\u56de 5.50000 m.next(3) = (1 + 10 + 3) \/ 3 \/\/ \u8fd4\u56de 4.66667 m.next(5) = (10 + 3 + 5) \/ 3 \/\/ \u8fd4\u56de 6.00000 <\/code><\/pre>\n<h2>\u89e3\u9898\u601d\u8def<\/h2>\n<p>\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u6765\u7ef4\u62a4\u5728\u7a97\u53e3\u4e2d\u7684\u503c\uff0c\u8fd9\u4e2a\u6570\u636e\u7ed3\u6784\u6709\u4e00\u4e2a\u8981\u6c42\uff0c\u5f53\u5b58\u50a8\u7684\u6570\u4e2a\u6570\u5927\u4e8e\u7a97\u53e3\u5927\u5c0f m \u65f6\uff0c\u9700\u8981\u5f39\u51fa\u6700\u5148\u8fdb\u5165\u7684\u6570\uff0c\u8fd9\u6b63\u597d\u65f6\u961f\u5217\u7684\u6027\u8d28\uff0c\u6240\u4ee5\u53ef\u4ee5\u7528\u961f\u5217\u6765\u7ef4\u62a4\u3002<\/p>\n<h2>\u7b97\u6cd5\uff1a\u961f\u5217\u6a21\u62df\u6ed1\u52a8\u7a97\u53e3<\/h2>\n<ol>\n<li>\u521d\u59cb\u5316\u65f6\u65b0\u5efa\u4e00\u4e2a\u961f\u5217\u3002<\/li>\n<li>\u6bcf\u6b21\u8c03\u7528 next(x)\u65f6\uff0c\u5c06 x \u52a0\u5165\u961f\u5217 1 \u3002<\/li>\n<li>\u5982\u679c\u961f\u5217\u957f\u5ea6\u5927\u4e8e m\uff0c\u5f39\u51fa\u961f\u9996\u3002<\/li>\n<li>\u8ba1\u7b97\u7ed3\u679c\u5e76\u8fd4\u56de\u3002<\/li>\n<\/ol>\n<h2>\u590d\u6742\u5ea6\u5206\u6790<\/h2>\n<p>\u8bbe\u7a97\u53e3\u5927\u5c0f\u4e3a m \u3002 \u65f6\u95f4\u590d\u6742\u5ea6<\/p>\n<ul>\n<li>\u5355\u6b21 next()\u65f6\u95f4\u590d\u6742\u5ea6 O(1)<\/li>\n<li>\u961f\u5217\u63d2\u5165\u548c\u5f39\u51fa\u90fd\u662f O(1)\u3002 \u7a7a\u95f4\u590d\u6742\u5ea6<\/li>\n<li>\u6700\u591a\u5b58\u50a8 m \u4e2a\u6570\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(m)\u3002<\/li>\n<\/ul>\n<pre><code>public class MovingAverage {      private Queue&lt;Integer&gt; queue;     private double sum = 0;     private int size;      \/** Initialize your data structure here. *\/     public MovingAverage(int size) {         queue = new LinkedList&lt;Integer&gt;();         this.size = size;     }          public double next(int val) {         sum += val;         if (queue.size() == size) {             sum = sum - queue.poll();         }         queue.offer(val);         return sum \/ queue.size();     } }  <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Google \u9762\u8bd5\u9898\uff1a\u6570\u636e\u6d41\u6ed1\u52a8\u7a97&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\/183985"}],"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=183985"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/183985\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=183985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=183985"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=183985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}