Cpp 36ms almost 1 line(avoids overflow).


  • 1
    B
    class Solution {
    public:
        int missingNumber(vector<int>& nums) {
            int i=0;
            return accumulate(nums.begin(), nums.end(), 0, [&](int x, int y){i++; return (x-y+i-1);})+i;
        }
    };

  • 0
    C

    brilliant idea!
    Maybe simplify the function to [&](int x, int y){ return x-y+i++; } ?


Log in to reply
 

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