偷跑写法
classSolution { public: intfindMin(vector<int>&nums) { sort(nums.begin(),nums.end()); returnnums[0]; } };
实际写法
classSolution { public: intfindMin(vector<int>&nums) { intl=0,r=nums.size()-1; while(l<r){ intmid=(r+l)/2; if(nums[mid]<nums[r]){ r=mid; } else{ l=mid+1; } } returnnums[l]; } };