Leetcode No.164 *
求排序后相邻两个数的最大值
思路:先利用C++标准模板库对vector进行排序,然后再依次寻找比较
代码:
//164 int maximumGap(vector<int>& nums) { if(nums.size()<2) return 0; vector<int> temp = nums; sort(temp.begin(),temp.end()); int diff=0; for(size_t i=1;i<temp.size();i++) if (diff<temp[i]-temp[i-1]) diff = temp[i] - temp[i-1]; return diff; }//164