-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path268. Missing Number
42 lines (33 loc) · 981 Bytes
/
268. Missing Number
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Runtime: 6 ms, faster than 12.23% of Java online submissions for Missing Number.
// Memory Usage: 39.3 MB, less than 81.66% of Java online submissions for Missing Number.
// class Solution {
// public int missingNumber(int[] nums) {
// HashSet<Integer> set=new HashSet<>();
// for(int i:nums){
// set.add(i);
// }
// for(int i=0;i<nums.length;i++)
// {
// if(!set.contains(i))
// return i;
// }
// return nums.length;
// }
// }
class Solution {
public int missingNumber(int[] nums) {
int a=0;
for(int i=0;i<=nums.length;i++)
{
a=a^i;
}
int b=0;
for(int i=0;i<nums.length;i++)
{
b=b^nums[i];
}
int res=a^b;
return res;
}
}
//Memory Usage: 40.1 MB, less than 100.00% of Java online submissions for Missing Number.