1、双while(超时)
2、while+if(12ms,81%;15.4MB,51%)
1 int minOperations(vector<int>& nums) { 2 int ins=0; 3 int i=0; 4 while(i+1<nums.size()){ 5 if(nums[i]>=nums[i+1]){ 6 //两数的差值+1即为单个递增次数 7 ins+=nums[i]-nums[i+1]+1; 8 //不要忘记修改后一个数 9 nums[i+1]=nums[i]+1; 10 } 11 i++; 12 } 13 return ins; 14 }