<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>production Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/production/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/production/</link>
	<description></description>
	<lastBuildDate>Mon, 16 Jul 2018 15:15:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>production Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/production/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 357. Count Numbers with Unique Digits</title>
		<link>https://zxi.mytechroad.com/blog/math/leetcode-357-count-numbers-with-unique-digits/</link>
					<comments>https://zxi.mytechroad.com/blog/math/leetcode-357-count-numbers-with-unique-digits/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Mon, 16 Jul 2018 15:14:53 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[permutation]]></category>
		<category><![CDATA[production]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=3196</guid>

					<description><![CDATA[<p>Problem Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x &#60; 10n. Example: Given n = 2, return 91. (The&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-357-count-numbers-with-unique-digits/">花花酱 LeetCode 357. Count Numbers with Unique Digits</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1><strong>Problem</strong></h1>
<p>Given a <b>non-negative</b> integer n, count all numbers with unique digits, x, where 0 ≤ x &lt; 10<sup>n</sup>.</p>
<p><b>Example:</b><br />
Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x &lt; 100, excluding <code>[11,22,33,44,55,66,77,88,99]</code>)</p>
<h1><strong>Solution: Math</strong></h1>
<p>f(0) = 1 (0)</p>
<p>f(1) = 10 (0 &#8211; 9)</p>
<p>f(2) = 9 * 9 (1-9 * (0 ~ 9 exclude the one from first digit))</p>
<p>f(3) = 9 * 9 * 8</p>
<p>f(4) = 9 * 9 * 8 * 7</p>
<p>&#8230;</p>
<p>f(x) = 0 if x &gt;= 10</p>
<p>ans = sum(f[1] ~ f[n])</p>
<p>Time complexity: O(1)</p>
<p>Space complexity: O(1)</p><pre class="crayon-plain-tag">// Author: Huahua
// Running time: 0 ms
class Solution {
public:
  int countNumbersWithUniqueDigits(int n) {
    if (n == 0) return 1;
    vector&lt;int&gt; f(11);    
    f[1] = 10;
    f[2] = 9 * 9;
    for (int i = 3; i &lt;= 10; ++i)
      f[i] = f[i - 1] * (10 - i + 1);
    int ans = 0;
    for (int i = 0; i &lt;= min(10, n); ++i)
      ans += f[i];
    return ans;
  }
};</pre><p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-357-count-numbers-with-unique-digits/">花花酱 LeetCode 357. Count Numbers with Unique Digits</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/math/leetcode-357-count-numbers-with-unique-digits/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
