LeetCode Q 268 - Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.
Solution
Code: Recursive approach
public int missingNumber(int[] nums) {
int sum = 0;
for (int num: nums) sum += num;
return (1 + nums.length) * num.length / 2 - sum;
}