@@ -0,0 +1,973 @@
+package math;%0A%0Apublic class Q268MissingNumber %7B%0A%0A    //Difficulty: Easy%0A    //TAG: Apple%0A    //TAG: Math%0A%0A    /**%0A     * 268. Missing Number%0A     * Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.%0A     *%0A     * Example 1:%0A     *%0A     * Input: %5B3,0,1%5D%0A     * Output: 2%0A     * Example 2:%0A     *%0A     * Input: %5B9,6,4,2,3,5,7,0,1%5D%0A     * Output: 8%0A     * Note:%0A     * Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?%0A     */%0A%0A    /*%0A    Solution:%0A    We can use formula sum = n * (n + 1) / 2 get the sum it should be , and realSum by add numbers in nums%0A    sum - realSum is the result%0A%0A    Time: O(n)%0A    Space: O(1)%0A     */%0A%0A    public int missingNumber(int%5B%5D nums) %7B%0A        if (nums == null) return 0;%0A        int sum = 0;%0A        for (int num: nums) sum += num;%0A        return nums.length * (nums.length + 1) / 2 - sum;%0A    %7D%0A%0A%7D%0A

268. Missing Number