Skip to content

Commit 43af467

Browse files
committed
Fix
1 parent 7a1f442 commit 43af467

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main/java/com/thealgorithms/bitmanipulation/NextHigherSameBitCount.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ private NextHigherSameBitCount() {
1212

1313
/**
1414
* 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.
1521
*
1622
* @param n the input number
1723
* @return the next higher integer with the same set bit count

0 commit comments

Comments
 (0)