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 bddcebe commit f119d27Copy full SHA for f119d27
MEDIUM/src/medium/MissingNumber.java
@@ -0,0 +1,14 @@
1
+package medium;
2
+
3
+public class MissingNumber {
4
+//This post has a very good explanation: https://discuss.leetcode.com/topic/24535/4-line-simple-java-bit-manipulate-solution-with-explaination
5
+ //we can simply XOR with the indices of the array since XOR twice the same number will become zero
6
+ public int missingNumber(int[] nums) {
7
+ int xor = 0, i = 0;
8
+ for(; i < nums.length; i++){
9
+ xor = xor^i^nums[i];
10
+ }
11
+ return xor^i;
12
13
14
+}
0 commit comments