Leet Code: Missing Number from Sorted Array of Numbers

 public class MissingNumber {


public static int missingNumber(int[] nums, int n)
{
int sum = ((n + 1) * (n + 2)) / 2; //
for (int i = 0; i < n; i++)
sum -= nums[i];
return sum;
}

public static void main(String[] args) {
int[] a = {1,2,4,5,6};
System.out.println(missingNumber(a,a.length));
}
}

Comments