Java solution


  • 1
    E
    public int missingNumber(int[] nums) {
            int sum = 0, n = nums.length;
            for (int a : nums) {
                sum += a;
            }
            return n * (n + 1) / 2 - sum;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.