-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMissingNumber.java
More file actions
29 lines (26 loc) · 619 Bytes
/
MissingNumber.java
File metadata and controls
29 lines (26 loc) · 619 Bytes
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
package Leetcode;
import java.util.Arrays;
/**
* @author szh
* @create 2018-09-14 23:44
**/
public class MissingNumber {
public int missingNumber(int[] nums) {
Arrays.sort(nums);
if(nums == null || nums.length == 0){
return 0;
}
int result =0;
int i =0;
for( ; i< nums.length ; i++){
result += (i ^ nums[i]);
}
result = result ^ i;
return result;
}
public static void main(String[] args) {
System.out.println(0 ^ 1);
System.out.println(1 ^ 2);
System.out.println((0 ^ 1));
}
}