My javascript solution


  • 0
    R

    (Expect SUM) - (nums' SUM) = Answer.
    Expect SUM = ((n+1)*n)/2

    var missingNumber = function(nums) {
        var sum = nums.reduce(function(a, b) {
            return a + b;
        });
        return ( ( 1+nums.length )*nums.length )/2 -sum;
    };

Log in to reply
 

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