Skip to content

Commit

Permalink
BitManipulationTest - missingNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
bky373 committed Jun 3, 2024
1 parent 9e2baff commit 0d7ad2f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/test/java/BitManipulationTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

public class BitManipulationTest {
Expand All @@ -22,5 +24,20 @@ void reverseBits() {
}
System.out.println("ans = " + ans);
System.out.println("Integer.toBinaryString(ans) = " + Integer.toBinaryString(ans));
assertThat(ans).isEqualTo(964176192);
}

/**
* https://leetcode.com/problems/missing-number/
*/
@Test
void missingNumber() {
int[] nums = new int[]{9, 6, 4, 2, 3, 5, 7, 0, 1};
int ans = nums.length;
for (int i=0; i<nums.length; i++) {
ans ^= i^nums[i];
}
System.out.println("ans = " + ans);
assertThat(ans).isEqualTo(8);
}
}

0 comments on commit 0d7ad2f

Please sign in to comment.