package com.fishercoder.solutions;

public class _268 {

    public static class Solution1 {
        /**
         * we could take advantage of the array indices
         * then a number xor with itself is zero, so after we xor the entire array with all of its indices, the missing number will show up.
         */
        public int missingNumber(int[] nums) {
            int xor = 0;
            int i = 0;
            for (; i < nums.length; i++) {
                xor ^= i ^ nums[i];
            }
            return xor ^ i;
        }
    }

}

@@ -540,10 +540,379 @@
 %0A    %7D%0A%0A
+    public static class Solution2 %7B%0A        public int missingNumber(int%5B%5D nums) %7B%0A            int n = nums.length;%0A            long sum = n + (n * n - n) / 2;//this is the formula to compute the sum for arithmetic sequence%0A            for (int i = 0; i %3C nums.length; i++) %7B%0A                sum -= nums%5Bi%5D;%0A            %7D%0A            return (int) sum;%0A        %7D%0A    %7D%0A%0A
 %7D%0A

add 268