<?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>boolean Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/boolean/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/boolean/</link>
	<description></description>
	<lastBuildDate>Tue, 14 Jan 2020 05:50:27 +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>boolean Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/boolean/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1318. Minimum Flips to Make a OR b Equal to c</title>
		<link>https://zxi.mytechroad.com/blog/bit/leetcode-1318-minimum-flips-to-make-a-or-b-equal-to-c/</link>
					<comments>https://zxi.mytechroad.com/blog/bit/leetcode-1318-minimum-flips-to-make-a-or-b-equal-to-c/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Tue, 14 Jan 2020 05:47:27 +0000</pubDate>
				<category><![CDATA[Bit]]></category>
		<category><![CDATA[bit]]></category>
		<category><![CDATA[boolean]]></category>
		<category><![CDATA[medum]]></category>
		<category><![CDATA[O(32)]]></category>
		<category><![CDATA[or]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=6093</guid>

					<description><![CDATA[<p>Given 3 positives numbers&#160;a,&#160;b&#160;and&#160;c. Return the minimum flips required in some bits of&#160;a&#160;and&#160;b&#160;to make (&#160;a&#160;OR&#160;b&#160;==&#160;c&#160;). (bitwise OR operation).Flip operation&#160;consists of change&#160;any&#160;single bit 1 to 0&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/bit/leetcode-1318-minimum-flips-to-make-a-or-b-equal-to-c/">花花酱 LeetCode 1318. Minimum Flips to Make a OR b Equal to c</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 3 positives numbers&nbsp;<code>a</code>,&nbsp;<code>b</code>&nbsp;and&nbsp;<code>c</code>. Return the minimum flips required in some bits of&nbsp;<code>a</code>&nbsp;and&nbsp;<code>b</code>&nbsp;to make (&nbsp;<code>a</code>&nbsp;OR&nbsp;<code>b</code>&nbsp;==&nbsp;<code>c</code>&nbsp;). (bitwise OR operation).<br>Flip operation&nbsp;consists of change&nbsp;<strong>any</strong>&nbsp;single bit 1 to 0 or change the bit 0 to 1&nbsp;in their binary representation.</p>



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



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2020/01/06/sample_3_1676.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> a = 2, b = 6, c = 5
<strong>Output:</strong> 3
<strong>Explanation: </strong>After flips a = 1 , b = 4 , c = 5 such that (<code>a</code> OR <code>b</code> == <code>c</code>)</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> a = 4, b = 2, c = 7
<strong>Output:</strong> 1
</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> a = 1, b = 2, c = 3
<strong>Output:</strong> 0
</pre>



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



<ul><li><code>1 &lt;= a &lt;= 10^9</code></li><li><code>1 &lt;= b&nbsp;&lt;= 10^9</code></li><li><code>1 &lt;= c&nbsp;&lt;= 10^9</code></li></ul>



<h2><strong>Solution: Bit operation</strong></h2>



<p>If the bit of c is 1, a / b at least has one 1. cost = 1 &#8211; ((a | b) &amp; 1)<br>If the bit of c is 0, a / b must be 0, cost = (a &amp; 1) + (b &amp; 1)</p>



<p>Time complexity: O(32)<br>Space complexity: O(1)</p>



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

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int minFlips(int a, int b, int c) {
    int count = 0;
    for (int i = 0; i &lt; 32; ++i) {      
      if (c &amp; 1) count += 1 - ((a | b) &amp; 1);
      else count += (a &amp; 1) + (b &amp; 1);
      a &gt;&gt;= 1;
      b &gt;&gt;= 1;
      c &gt;&gt;= 1;
    }
    return count;
  }
};</pre>
</div></div>



<p></p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/bit/leetcode-1318-minimum-flips-to-make-a-or-b-equal-to-c/">花花酱 LeetCode 1318. Minimum Flips to Make a OR b Equal to c</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/bit/leetcode-1318-minimum-flips-to-make-a-or-b-equal-to-c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
