I think we can take this problem as a MATH problem, the sum should be (n+0)*(n+1)/2, then minus each of the element in the array.

```
public class Solution {
public int missingNumber(int[] nums) {
int n = nums.length;
int sum = n*(n + 1)/2;
for(int i : nums)
sum-= i;
return sum;
}
}
```