<?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>num Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/num/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/num/</link>
	<description></description>
	<lastBuildDate>Mon, 28 Feb 2022 14:58:34 +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>num Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/num/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 2180. Count Integers With Even Digit Sum</title>
		<link>https://zxi.mytechroad.com/blog/string/leetcode-2180-count-integers-with-even-digit-sum/</link>
					<comments>https://zxi.mytechroad.com/blog/string/leetcode-2180-count-integers-with-even-digit-sum/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Mon, 28 Feb 2022 13:51:26 +0000</pubDate>
				<category><![CDATA[String]]></category>
		<category><![CDATA[base10]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[num]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=9519</guid>

					<description><![CDATA[<p>Given a positive integer&#160;num, return&#160;the number of positive integers&#160;less than or equal to&#160;num&#160;whose digit sums are&#160;even. The&#160;digit sum&#160;of a positive integer is the sum of&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-2180-count-integers-with-even-digit-sum/">花花酱 LeetCode 2180. Count Integers With Even Digit Sum</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>Given a positive integer&nbsp;<code>num</code>, return&nbsp;<em>the number of positive integers&nbsp;<strong>less than or equal to</strong></em>&nbsp;<code>num</code>&nbsp;<em>whose digit sums are&nbsp;<strong>even</strong></em>.</p>



<p>The&nbsp;<strong>digit sum</strong>&nbsp;of a positive integer is the sum of all its digits.</p>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> num = 4
<strong>Output:</strong> 2
<strong>Explanation:</strong>
The only integers less than or equal to 4 whose digit sums are even are 2 and 4.    
</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> num = 30
<strong>Output:</strong> 14
<strong>Explanation:</strong>
The 14 integers less than or equal to 30 whose digit sums are even are
2, 4, 6, 8, 11, 13, 15, 17, 19, 20, 22, 24, 26, and 28.
</pre>



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



<ul><li><code>1 &lt;= num &lt;= 1000</code></li></ul>



<h2><strong>Solution: Brute Force</strong></h2>



<p>Use std::to_string to convert an integer to string.</p>



<p>Time complexity: O(nlgn)<br>Space complexity: O(lgn)</p>



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

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int countEven(int num) {
    int ans = 0;
    for (int i = 1; i &lt;= num; ++i) {
      int sum = 0;
      for (char c : to_string(i))
        sum += (c - '0');
      if (sum % 2 == 0) ++ans;
    }
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-2180-count-integers-with-even-digit-sum/">花花酱 LeetCode 2180. Count Integers With Even Digit Sum</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-2180-count-integers-with-even-digit-sum/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
