title: Find the closest integer with same weight O(1)
body: <p>I am solving this problem: </p>
  
  <p>The count of ones in binary representation of integer number is called the weight of that number. The following algorithm finds the closest integer with the same weight. For example, for 123 (0111 1011)₂, the closest integer number is 125 (0111 1101)₂.</p>
  
  <p>The solution for O(n)
  where n is the width of the input number is by swapping the positions of the  first pair of consecutive bits that differ.</p>
  
  <p>Could someone give me some hints for solving in it in O(1) runtime and space ? </p>
  
  <p>Thanks</p>