https://leetcode.com/problems/missing-number/
class Solution { public: int missingNumber(vector<int>& nums) { int size=nums.size(); int * myArray=new int[size+1]; memset(myArray,0,sizeof(int)*(size+1)); for(int i=0;i<size;i++) { myArray[nums[i]]=1; } int index=0; for(;index<size+1;index++) { if(myArray[index]==0) break; } return index; } };
时间: 2024-10-14 11:42:40