Skip to content

Commit fb986c4

Browse files
authored
Create missingnumber.java
1 parent 7f407be commit fb986c4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

missingnumber.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
try to implement using xor operation
3+
*/
4+
5+
class Solution {
6+
public int missingNumber(int[] nums) {
7+
int sum = 0;
8+
for(int i=0;i<nums.length;i++){
9+
sum = sum + nums[i];
10+
}
11+
int ans = (nums.length*(nums.length+1))/2;
12+
return ans-sum;
13+
14+
15+
}
16+
}

0 commit comments

Comments
 (0)