<?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>number Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/number/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/number/</link>
	<description></description>
	<lastBuildDate>Wed, 11 Jul 2018 01:32:47 +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>number Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/number/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 816. Ambiguous Coordinates</title>
		<link>https://zxi.mytechroad.com/blog/string/leetcode-816-ambiguous-coordinates/</link>
					<comments>https://zxi.mytechroad.com/blog/string/leetcode-816-ambiguous-coordinates/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 15 Apr 2018 03:15:39 +0000</pubDate>
				<category><![CDATA[String]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[valid]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=2484</guid>

					<description><![CDATA[<p>Problem 题目大意：把一串数字分成两段，输出所有合法的分法（可以加小数点）。 https://leetcode.com/problems/ambiguous-coordinates/description/ We had some 2-dimensional coordinates, like "(1, 3)" or "(2, 0.5)".  Then, we removed all commas, decimal points, and spaces, and ended up with the string S. &#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-816-ambiguous-coordinates/">花花酱 LeetCode 816. Ambiguous Coordinates</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>题目大意：把一串数字分成两段，输出所有合法的分法（可以加小数点）。</p>
<p><a href="https://leetcode.com/problems/ambiguous-coordinates/description/">https://leetcode.com/problems/ambiguous-coordinates/description/</a></p>
<p>We had some 2-dimensional coordinates, like <code>"(1, 3)"</code> or <code>"(2, 0.5)"</code>.  Then, we removed all commas, decimal points, and spaces, and ended up with the string <code>S</code>.  Return a list of strings representing all possibilities for what our original coordinates could have been.</p>
<p>Our original representation never had extraneous zeroes, so we never started with numbers like &#8220;00&#8221;, &#8220;0.0&#8221;, &#8220;0.00&#8221;, &#8220;1.0&#8221;, &#8220;001&#8221;, &#8220;00.01&#8221;, or any other number that can be represented with less digits.  Also, a decimal point within a number never occurs without at least one digit occuring before it, so we never started with numbers like &#8220;.1&#8221;.</p>
<p>The final answer list can be returned in any order.  Also note that all coordinates in the final answer have exactly one space between them (occurring after the comma.)</p>
<pre class="crayon:false"><strong>Example 1:</strong>
<strong>Input:</strong> "(123)"
<strong>Output:</strong> ["(1, 23)", "(12, 3)", "(1.2, 3)", "(1, 2.3)"]
</pre>
<pre class="crayon:false"><strong>Example 2:</strong>
<strong>Input:</strong> "(00011)"
<strong>Output:</strong>  ["(0.001, 1)", "(0, 0.011)"]
<strong>Explanation:</strong> 
0.0, 00, 0001 or 00.01 are not allowed.
</pre>
<pre class="crayon:false"><strong>Example 3:</strong>
<strong>Input:</strong> "(0123)"
<strong>Output:</strong> ["(0, 123)", "(0, 12.3)", "(0, 1.23)", "(0.1, 23)", "(0.1, 2.3)", "(0.12, 3)"]
</pre>
<pre class="crayon:false"><strong>Example 4:</strong>
<strong>Input:</strong> "(100)"
<strong>Output:</strong> [(10, 0)]
<strong>Explanation:</strong> 
1.0 is not allowed.
</pre>
<h1><strong>Solution: Brute Force</strong></h1>
<p>Time complexity: O(n^3)</p>
<p>Space complexity: O(n)</p>
<p>C++</p><pre class="crayon-plain-tag">// Author: Huahua
// Running time: 16 ms
class Solution {
public:
  vector&lt;string&gt; ambiguousCoordinates(string S) {
    vector&lt;string&gt; ans;
    int n = S.length();
    for (int l1 = 1; l1 &lt;= n - 3; ++l1) {      
      int l2 = n - l1 - 2;
      string s1 = S.substr(1, l1);
      string s2 = S.substr(l1 + 1, l2);      
      if (valid(s1) &amp;&amp; valid(s2))
        ans.push_back("(" + s1 + ", " + s2 + ")");
      
      for (int i = 0; i &lt; l1; ++i) {
        string ts1 = s1;
        if (i &gt; 0) ts1.insert(i, ".");        
        if (!valid(ts1)) continue;
        for (int j = 0; j &lt; l2; ++j) {
          if (i == 0 &amp;&amp; j == 0) continue;
          string ts2 = s2;
          if (j &gt; 0) ts2.insert(j, ".");          
          if (!valid(ts2)) continue;          
          ans.push_back("(" + ts1 + ", " + ts2 + ")");
        }
      }
    }
    
    return ans;
  }
private:    
  bool valid(const string&amp; s) {
    bool p = false; // has "."
    bool d = false; // has digits in front of "."
    int zeros = 0;  // leading zeros
    int i = 0;
    while (s[zeros] == '0' &amp;&amp; zeros &lt; s.length()) ++zeros;
    for (int i = zeros; i &lt; s.length(); ++i) {
      if (!p &amp;&amp; isdigit(s[i])) d = true;
      if (s[i] == '.') p = true;
    }
    if (zeros == 1 &amp;&amp; s != "0" &amp;&amp; !p || zeros &gt; 1) return false;
    if (p &amp;&amp; (s.back() == '0' || s.back() == '.' || zeros &gt; 0 &amp;&amp; d)) return false;    
    return true;
  }
};</pre><p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-816-ambiguous-coordinates/">花花酱 LeetCode 816. Ambiguous Coordinates</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/string/leetcode-816-ambiguous-coordinates/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 268. Missing Number</title>
		<link>https://zxi.mytechroad.com/blog/math/leetcode-268-missing-number/</link>
					<comments>https://zxi.mytechroad.com/blog/math/leetcode-268-missing-number/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sat, 09 Sep 2017 20:11:14 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[missing]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[sum]]></category>
		<category><![CDATA[xor]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=180</guid>

					<description><![CDATA[<p>Problem: Given an array containing n distinct numbers taken from 0, 1, 2, &#8230;, n, find the one that is missing from the array. For&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-268-missing-number/">花花酱 LeetCode 268. Missing Number</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><iframe width="500" height="375" src="https://www.youtube.com/embed/z0p_FBatGWM?feature=oembed" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></p>
<p><strong>Problem:</strong></p>
<p>Given an array containing n distinct numbers taken from 0, 1, 2, &#8230;, n, find the one that is missing from the array.</p>
<p>For example,<br />
Given nums = [0, 1, 3] return 2.</p>
<p>Note:<br />
Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?</p>
<p>&nbsp;</p>
<p><strong>Idea:</strong></p>
<p>sum / xor</p>
<p><a href="http://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/268-ep44.png"><img class="alignnone size-full wp-image-183" src="http://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/268-ep44.png" alt="" width="960" height="540" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/268-ep44.png 960w, https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/268-ep44-300x169.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/268-ep44-768x432.png 768w, https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/268-ep44-624x351.png 624w" sizes="(max-width: 960px) 100vw, 960px" /></a></p>
<p><strong>Solution:</strong></p><pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
    // Solution 1: Sum
    int missingNumber(vector&lt;int&gt;&amp; nums) {
        int n = nums.size();
        int x = (0+n)*(n+1)/2 - accumulate(nums.begin(), nums.end(), 0);
        return x;
    }
    
    // Solution 2: XOR
    int missingNumber(vector&lt;int&gt;&amp; nums) {
        int n = nums.size();
        int x = 0;
        for(int i=1;i&lt;=n;++i)
            x = x ^ i ^ nums[i-1];
        return x;
    }
};</pre><p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-268-missing-number/">花花酱 LeetCode 268. Missing Number</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-268-missing-number/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
