We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7a1f442 commit 43af467Copy full SHA for 43af467
src/main/java/com/thealgorithms/bitmanipulation/NextHigherSameBitCount.java
@@ -12,6 +12,12 @@ private NextHigherSameBitCount() {
12
13
/**
14
* Finds the next higher integer with the same number of set bits.
15
+ * Steps:
16
+ * 1. Find {@code c}, the rightmost set bit of {@code n}.
17
+ * 2. Find {@code r}, the rightmost set bit of {@code n + c}.
18
+ * 3. Swap the bits of {@code r} and {@code n} to the right of {@code c}.
19
+ * 4. Shift the bits of {@code r} and {@code n} to the right of {@code c} to the rightmost.
20
+ * 5. Combine the results of steps 3 and 4.
21
*
22
* @param n the input number
23
* @return the next higher integer with the same set bit count
0 commit comments