```
public int missingNumber(int[] nums) {
int total = 0;
int n = nums.length;
int sum = (n * (n + 1)) / 2; //Formula for the sum of all Natural Numbers up to N
for(int i : nums) total += i; //total of elements in the array
return sum - total; //The difference of the sum and the total is the missing number
```