<?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>enumerate Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/enumerate/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/enumerate/</link>
	<description></description>
	<lastBuildDate>Sun, 05 Dec 2021 06:17:28 +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>enumerate Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/enumerate/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 2094. Finding 3-Digit Even Numbers</title>
		<link>https://zxi.mytechroad.com/blog/hashtable/leetcode-2094-finding-3-digit-even-numbers/</link>
					<comments>https://zxi.mytechroad.com/blog/hashtable/leetcode-2094-finding-3-digit-even-numbers/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 05 Dec 2021 06:16:33 +0000</pubDate>
				<category><![CDATA[Hashtable]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[hashtable]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=9016</guid>

					<description><![CDATA[<p>You are given an integer array&#160;digits, where each element is a digit. The array may contain duplicates. You need to find&#160;all&#160;the&#160;unique&#160;integers that follow the given&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/hashtable/leetcode-2094-finding-3-digit-even-numbers/">花花酱 LeetCode 2094. Finding 3-Digit Even Numbers</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>You are given an integer array&nbsp;<code>digits</code>, where each element is a digit. The array may contain duplicates.</p>



<p>You need to find&nbsp;<strong>all</strong>&nbsp;the&nbsp;<strong>unique</strong>&nbsp;integers that follow the given requirements:</p>



<ul><li>The integer consists of the&nbsp;<strong>concatenation</strong>&nbsp;of&nbsp;<strong>three</strong>&nbsp;elements from&nbsp;<code>digits</code>&nbsp;in&nbsp;<strong>any</strong>&nbsp;arbitrary order.</li><li>The integer does not have&nbsp;<strong>leading zeros</strong>.</li><li>The integer is&nbsp;<strong>even</strong>.</li></ul>



<p>For example, if the given&nbsp;<code>digits</code>&nbsp;were&nbsp;<code>[1, 2, 3]</code>, integers&nbsp;<code>132</code>&nbsp;and&nbsp;<code>312</code>&nbsp;follow the requirements.</p>



<p>Return&nbsp;<em>a&nbsp;<strong>sorted</strong>&nbsp;array of the unique integers.</em></p>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> digits = [2,1,3,0]
<strong>Output:</strong> [102,120,130,132,210,230,302,310,312,320]
<strong>Explanation:</strong> 
All the possible integers that follow the requirements are in the output array. 
Notice that there are no <strong>odd</strong> integers or integers with <strong>leading zeros</strong>.</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> digits = [2,2,8,8,2]
<strong>Output:</strong> [222,228,282,288,822,828,882]
<strong>Explanation:</strong> 
The same digit can be used as many times as it appears in <code>digits</code>. 
In this example, the digit 8 is used twice each time in 288, 828, and 882. 
</pre>



<p><strong>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> digits = [3,7,5]
<strong>Output:</strong> []
<strong>Explanation:</strong> 
No <strong>even</strong> integers can be formed using the given digits.
</pre>



<p><strong>Example 4:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> digits = [0,2,0,0]
<strong>Output:</strong> [200]
<strong>Explanation:</strong> 
The only valid integer that can be formed with three digits and <strong>no leading zeros</strong> is 200.
</pre>



<p><strong>Example 5:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> digits = [0,0,0]
<strong>Output:</strong> []
<strong>Explanation:</strong> 
All the integers that can be formed have <strong>leading zeros</strong>. Thus, there are no valid integers.
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>3 &lt;=&nbsp;digits.length &lt;= 100</code></li><li><code>0 &lt;= digits[i] &lt;= 9</code></li></ul>



<h2><strong>Solution: Enumerate all three digits even numbers</strong></h2>



<p>Check 100, 102, &#8230; 998. Use a hashtable to check whether all digits are covered by the given digits.</p>



<p>Time complexity: O(1000*lg(1000))<br>Space complexity: O(10)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  vector&lt;int&gt; findEvenNumbers(vector&lt;int&gt;&amp; digits) {
    vector&lt;int&gt; counts(10);
    for (int d : digits) ++counts[d];
    vector&lt;int&gt; ans;
    for (int x = 100; x &lt; 1000; x += 2) {
      bool valid = true;
      vector&lt;int&gt; c(10);
      for (int t = x; t &gt; 0; t /= 10)
        valid &amp;= (++c[t % 10] &lt;= counts[t % 10]);           
      if (valid) ans.push_back(x);
    }
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/hashtable/leetcode-2094-finding-3-digit-even-numbers/">花花酱 LeetCode 2094. Finding 3-Digit Even Numbers</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/hashtable/leetcode-2094-finding-3-digit-even-numbers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Python-Like enumerate() In C++17 &#8211; C++ Weekly EP1</title>
		<link>https://zxi.mytechroad.com/blog/c/python-like-enumerate-in-c17/</link>
					<comments>https://zxi.mytechroad.com/blog/c/python-like-enumerate-in-c17/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 17 May 2020 21:34:20 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[auto]]></category>
		<category><![CDATA[c++17]]></category>
		<category><![CDATA[constexpr]]></category>
		<category><![CDATA[enumerate]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=6774</guid>

					<description><![CDATA[<p>[crayon-6639fa6848513554344221/]</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/c/python-like-enumerate-in-c17/">Python-Like enumerate() In C++17 &#8211; C++ Weekly EP1</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Python-Like enumerate() In C++17 - C++ Weekly EP1" width="500" height="375" src="https://www.youtube.com/embed/ENpgbTrrebo?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;list&gt;
#include &lt;tuple&gt;
using namespace std;

// Python-Like enumerate() In C++17
// http://reedbeta.com/blog/python-like-enumerate-in-cpp17/
template &lt;typename T,
          typename TIter = decltype(std::begin(std::declval&lt;T&gt;())),
          typename = decltype(std::end(std::declval&lt;T&gt;()))&gt;
constexpr auto enumerate(T &amp;&amp; iterable) {
  struct iterator {
    int i;
    TIter iter;
    bool operator != (const iterator &amp; other) const { return iter != other.iter; }
    void operator ++ () { ++i; ++iter; }
    auto operator * () const { return std::tie(i, *iter); }
  };
  struct iterable_wrapper {
    T iterable;
    auto begin() { return iterator{ 0, std::begin(iterable) }; }
    auto end() { return iterator{ 0, std::end(iterable) }; }
  };
  // return iterable_wrapper{ iterable }; // this makes a copy if iterable is a rvalue.
  return iterable_wrapper{ std::forward&lt;T&gt;(iterable) };  
}

struct A {
  int val;
  A(int val): val(val) { cout &lt;&lt; &quot;A(int)&quot; &lt;&lt; endl; }
  A(const A&amp; a): val(a.val) { cout &lt;&lt; &quot;A(A&amp;)&quot; &lt;&lt; endl; }
  A(A&amp;&amp; a): val(a.val) { cout &lt;&lt; &quot;A(A&amp;&amp;)&quot; &lt;&lt; endl; }    
};

int main(int argc, char** argv) {
  vector&lt;int&gt; arr{1, 2, 4};  
  
  for (size_t i = 0; i &lt; arr.size(); ++i)
    cout &lt;&lt; i &lt;&lt; &quot; &quot; &lt;&lt; arr[i] &lt;&lt; endl;

  size_t idx = 0;
  for (int v : arr)
    cout &lt;&lt; idx++ &lt;&lt; &quot; &quot; &lt;&lt; v &lt;&lt; endl;

  for (auto it = begin(arr); it != end(arr); ++it)
    cout &lt;&lt; distance(begin(arr), it) &lt;&lt; &quot; &quot; &lt;&lt; *it &lt;&lt; endl;
  

  for (const auto&amp; [i, v] : enumerate(arr))
    cout &lt;&lt; i &lt;&lt; &quot; &quot; &lt;&lt; v &lt;&lt; endl;

  list&lt;string&gt; lst{&quot;hello&quot;, &quot;world!&quot;};  

  for (const auto&amp; [i, v] : enumerate(lst))
    cout &lt;&lt; i &lt;&lt; &quot; &quot; &lt;&lt; v &lt;&lt; endl;

  for (const auto&amp; [i, v] : enumerate(string(&quot;abcde&quot;)))
    cout &lt;&lt; i &lt;&lt; &quot; &quot; &lt;&lt; v &lt;&lt; endl;

  vector&lt;A&gt; vec;
  vec.reserve(3);
  vec.emplace_back(1);
  vec.emplace_back(2);
  vec.emplace_back(4);

  for (const auto&amp; [i, v] : enumerate(vec))
    cout &lt;&lt; i &lt;&lt; &quot; &quot; &lt;&lt; v.val &lt;&lt; endl;

  for (const auto&amp; [i, v] : enumerate(vector&lt;A&gt;{A(1), A(2), A(4)}))
    cout &lt;&lt; i &lt;&lt; &quot; &quot; &lt;&lt; v.val &lt;&lt; endl;

  return 0;
}</pre>
</div></div>



<p></p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/c/python-like-enumerate-in-c17/">Python-Like enumerate() In C++17 &#8211; C++ Weekly EP1</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/c/python-like-enumerate-in-c17/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
