One line C++ code


  • 1
    class Solution {
    public:
        int missingNumber(vector<int>& nums) {
            return 0.5 * nums.size() * (nums.size() + 1) - accumulate(nums.begin(), nums.end(), 0);
        }
    };
    

Log in to reply
 

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