等差数列求值
1 class Solution { 2 public: 3 int missingNumber(vector<int>& nums) { 4 int n=nums.size(); 5 int k=n*(n+1)/2; 6 for(int i=0;i<n;i++) 7 k-=nums[i]; 8 return k; 9 } 10 };
等差数列求值
1 class Solution { 2 public: 3 int missingNumber(vector<int>& nums) { 4 int n=nums.size(); 5 int k=n*(n+1)/2; 6 for(int i=0;i<n;i++) 7 k-=nums[i]; 8 return k; 9 } 10 };