{"id":315992,"date":"2021-02-03T22:11:32","date_gmt":"2021-02-03T14:11:32","guid":{"rendered":"http:\/\/4563.org\/?p=315992"},"modified":"2021-02-03T22:11:32","modified_gmt":"2021-02-03T14:11:32","slug":"%e4%b9%9d%e7%ab%a0%e7%ae%97%e6%b3%95-%e4%ba%9a%e9%a9%ac%e9%80%8a%e9%9d%a2%e8%af%95%e9%a2%98%ef%bc%9a-fizz-buzz-%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=315992","title":{"rendered":"\u4e5d\u7ae0\u7b97\u6cd5 | \u4e9a\u9a6c\u900a\u9762\u8bd5\u9898\uff1a Fizz Buzz \u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4e5d\u7ae0\u7b97\u6cd5 | \u4e9a\u9a6c\u900a\u9762\u8bd5\u9898\uff1a Fizz Buzz \u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hakunamatata11 <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p><strong>\u63cf\u8ff0<\/strong><\/p>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570<em>n<\/em>. \u4ece <em>1<\/em> \u5230 <em>n<\/em> \u6309\u7167\u4e0b\u9762\u7684\u89c4\u5219\u6253\u5370\u6bcf\u4e2a\u6570\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u8fd9\u4e2a\u6570\u88ab 3 \u6574\u9664\uff0c\u6253\u5370 fizz.<\/li>\n<li>\u5982\u679c\u8fd9\u4e2a\u6570\u88ab 5 \u6574\u9664\uff0c\u6253\u5370 buzz.<\/li>\n<li>\u5982\u679c\u8fd9\u4e2a\u6570\u80fd\u540c\u65f6\u88ab 3 \u548c 5 \u6574\u9664\uff0c\u6253\u5370 fizz buzz.<\/li>\n<li>\u5982\u679c\u8fd9\u4e2a\u6570\u65e2\u4e0d\u80fd\u88ab 3 \u6574\u9664\u4e5f\u4e0d\u80fd\u88ab 5 \u6574\u9664\uff0c\u6253\u5370\u6570\u5b57\u672c\u8eab\u3002<\/li>\n<\/ul>\n<p>\u5728\u7ebf\u8bc4\u6d4b\u5730\u5740<\/p>\n<p><strong>\u6837\u4f8b<\/strong><\/p>\n<p>\u6bd4\u5982 <em>n<\/em> = 15, \u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff1a<\/p>\n<pre><code>[   \"1\", \"2\", \"fizz\",   \"4\", \"buzz\", \"fizz\",   \"7\", \"8\", \"fizz\",   \"buzz\", \"11\", \"fizz\",   \"13\", \"14\", \"fizz buzz\" ]  <\/code><\/pre>\n<p><strong>\u6311\u6218\uff1a<\/strong><\/p>\n<p>\u4f60\u662f\u5426\u53ef\u4ee5\u53ea\u7528\u4e00\u4e2a if \u6765\u5b9e\u73b0<\/p>\n<p><strong>\u9898\u89e3\uff1a<\/strong><\/p>\n<p>\u6709\u7684\u9762\u8bd5\u5b98\u4f1a\u8981\u6c42\u4f60\u80fd\u4e0d\u80fd\u53ea\u7528\u4e00\u4e2a if \u8bed\u53e5\u6765\u5b8c\u6210\u8fd9\u4e2a\u9898\uff0c\u8fd9\u662f\u4e00\u4e2a\u53c2\u8003\u3002\u7a81\u7834\u70b9\u5728\u4e8e\uff1a\u90a3\u6211\u53ef\u4ee5\u7528 while \u5440~<\/p>\n<pre><code>class Solution {     \/**      * param n: As description.      * return: A list of strings.      *\/     public ArrayList&lt;String&gt; fizzBuzz(int n) {         ArrayList&lt;String&gt; results = new ArrayList&lt;String&gt;();         int i = 1;         \/\/p3 \u8868\u793a 3 \u7684\u591a\u5c11\u500d\uff0cp5 \u8868\u793a 5 \u7684\u591a\u5c11\u500d         int p3 = 1, p5 = 1;          while (i &lt;= n) {           while (i &lt; p3 * 3 &amp;&amp; i &lt; p5 * 5) {             results.add(i + \"\");             i++;           }            if (i &lt;= n &amp;&amp; p3 * 3 == p5 * 5) {             results.add(\"fizz buzz\");             p3++;             p5++;             i++;             continue;           }            while (i &lt;= n &amp;&amp; p3 * 3 &lt;= i) {             results.add(\"fizz\");             p3++;             i++;           }            while (i &lt;= n &amp;&amp; p5 * 5 &lt;= i) {             results.add(\"buzz\");             p5++;             i++;           }         }          return results;     } }  <\/code><\/pre>\n<p>\u66f4\u591a\u9898\u89e3\u53c2\u8003\uff1a\u4e5d\u7ae0\u7b97\u6cd5<\/p>\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>\u4e5d\u7ae0\u7b97\u6cd5 | \u4e9a\u9a6c\u900a\u9762\u8bd5\u9898\uff1a Fi&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\/315992"}],"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=315992"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/315992\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=315992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=315992"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=315992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}