{"id":97466,"date":"2020-05-15T12:31:42","date_gmt":"2020-05-15T04:31:42","guid":{"rendered":"http:\/\/4563.org\/?p=97466"},"modified":"2020-05-15T12:31:42","modified_gmt":"2020-05-15T04:31:42","slug":"%e8%af%b7%e5%b8%ae%e6%88%91%e7%9c%8b%e7%9c%8b%e4%b8%ba%e5%95%a5%e6%88%91%e8%bf%99%e4%b8%aa%e4%bb%a3%e7%a0%81%e4%b8%8d%e5%af%b9%e5%91%a2%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=97466","title":{"rendered":"\u8bf7\u5e2e\u6211\u770b\u770b\u4e3a\u5565\u6211\u8fd9\u4e2a\u4ee3\u7801\u4e0d\u5bf9\u5462\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u5e2e\u6211\u770b\u770b\u4e3a\u5565\u6211\u8fd9\u4e2a\u4ee3\u7801\u4e0d\u5bf9\u5462\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Newyorkcity <\/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>leetcode 1012<\/p>\n<pre><code>public class Solution {     public int numDupDigitsAtMostN(int N) {         if (N &lt; 11) return 0;         String Nstr = String.valueOf(N);         int Nlength = Nstr.length();         int nonrepeatableNumTotal = 0;          \/\/\u9996\u5148\u6570\u6e05\u695a\u4f4d\u6570\u5c0f\u4e8e N \u7684\u6570\u4e2d\u53d1\u751f\u4e86\u91cd\u590d\u7684\u6570         \/\/\u4f4d\u6570\u7b49\u4e8e n \u65f6\uff0c\u6700\u9ad8\u4f4d\u4e5f\u5c31\u662f\u7b2c\u4e00\u4f4d\u53ea\u6709 9 \u79cd\u9009\u62e9\uff08\u4e0d\u80fd\u9009 0 \uff09\u4f46         \/\/\u4f46\u4e4b\u540e\u7684 n-1 \u4f4d\u53ef\u4ece(10-1)\u4e2a\u6570\u5b57\u4e2d\u4efb\u4e00\u9009\u62e9         for (int i = 0; i + 1 &lt; Nlength; i++) {             nonrepeatableNumTotal += (9 * A(i, 9));         }           \/\/\u7136\u540e\u6570\u6e05\u695a\u548c\u7ed9\u51fa\u7684\u6570\u636e\u7b49\u4f4d\u6570\u7684\u6570\u91cc\u6709\u53d1\u751f\u4e86\u91cd\u590d\u7684\u6570         \/\/\u7531\u4e8e\u89c4\u5b9a\u4e86\u4f4d\u6570\u8981\u76f8\u540c\uff0c\u6240\u4ee5\u6700\u9ad8\u4f4d\u5373 i==1 \u65f6\u4e0d\u80fd\u53d6 0\uff0c\u6545\u6709 t-1         for (int i = 0; i &lt; Nlength; i++) {             int t = Nstr.charAt(i) - '0';             if (i == 0) {                 nonrepeatableNumTotal += ((t - 1) * A(Nlength - 1, 9));             } else {                 nonrepeatableNumTotal += (t * A(Nlength - 1 - i, 9 - i));             }         }          int used = 0;         for (char c : Nstr.toCharArray()) {             int t = (1 &lt;&lt; (c - '0'));             if ((used &amp; t) == 0) {                 used |= t;             } else {                 return N - nonrepeatableNumTotal + 1;             }         }          return N - nonrepeatableNumTotal;     }      private int factorial(int n) {         if (n == 1 || n == 0) return 1;         return n * factorial(n - 1);     }      private int A(int m, int n) {         return factorial(n) \/ factorial(n - m);     } } <\/code><\/pre>\n<p>\u8c22\u8c22<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1625082\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lysS <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             php \u6211\u8fd9\u6837\u5199\u7684, \u601d\u8def\u5c31\u90a3\u4e48\u51e0\u79cd<br \/>https:\/\/gist.github.com\/lysShub\/d313e16861e6e97deed686e15a4e60f2 <button onclick=\"lazyGist(this)\">\u00a0\u663e\u793a Gist \u4ee3\u7801\u00a0<\/button> <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u5e2e\u6211\u770b\u770b\u4e3a\u5565\u6211\u8fd9\u4e2a\u4ee3\u7801\u4e0d\u5bf9\u5462\uff1f &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\/97466"}],"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=97466"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/97466\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=97466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=97466"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=97466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}