java.lang.Object
g1601_1700.s1611_minimum_one_bit_operations_to_make_integers_zero.Solution

public class Solution extends Object
1611 - Minimum One Bit Operations to Make Integers Zero.<p>Hard</p> <p>Given an integer <code>n</code>, you must transform it into <code>0</code> using the following operations any number of times:</p> <ul> <li>Change the rightmost (<code>0<sup>th</sup></code>) bit in the binary representation of <code>n</code>.</li> <li>Change the <code>i<sup>th</sup></code> bit in the binary representation of <code>n</code> if the <code>(i-1)<sup>th</sup></code> bit is set to <code>1</code> and the <code>(i-2)<sup>th</sup></code> through <code>0<sup>th</sup></code> bits are set to <code>0</code>.</li> </ul> <p>Return <em>the minimum number of operations to transform</em> <code>n</code> <em>into</em> <code>0</code><em>.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 3</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The binary representation of 3 is &ldquo;11&rdquo;.</p> <p>&ldquo;11&rdquo; -> &ldquo;01&rdquo; with the 2<sup>nd</sup> operation since the 0<sup>th</sup> bit is 1.</p> <p>&ldquo;01&rdquo; -> &ldquo;00&rdquo; with the 1<sup>st</sup> operation.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 6</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The binary representation of 6 is &ldquo;110&rdquo;.</p> <p>&ldquo;110&rdquo; -> &ldquo;010&rdquo; with the 2<sup>nd</sup> operation since the 1<sup>st</sup> bit is 1 and 0<sup>th</sup> through 0<sup>th</sup> bits are 0.</p> <p>&ldquo;010&rdquo; -> &ldquo;011&rdquo; with the 1<sup>st</sup> operation.</p> <p>&ldquo;011&rdquo; -> &ldquo;001&rdquo; with the 2<sup>nd</sup> operation since the 0<sup>th</sup> bit is 1.</p> <p>&ldquo;001&rdquo; -> &ldquo;000&rdquo; with the 1<sup>st</sup> operation.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>0 <= n <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minimumOneBitOperations

      public int minimumOneBitOperations(int n)