leetcode Maximum Gap
来源:互联网 发布:工资结算数据流程图 编辑:程序博客网 时间:2024/06/05 20:20
class Solution {// 木桶排序//鸽巢原理public: int maximumGap(vector<int>& nums) { if (nums.size() < 2) return 0; int _min = *min_element(nums.begin(), nums.end()); int _max = *max_element(nums.begin(), nums.end()); double interval = (_max - _min) / (double)nums.size(); vector<pair<int, int>> vec(nums.size(), make_pair(0x7fffffff, 1)); for (int i = 0; i < nums.size(); ++i){ int k = (nums[i] - _min) / interval; vec[k].first = min (vec[k].first, nums[i]); vec[k].second = max (vec[k].second, nums[i]); } int ret = 0, last_max = 0; for (int i = 0; i < vec.size(); ++i){ if (vec[i].first <= vec[i].second){ if (last_max > 0) ret = max (ret, vec[i].first - last_max); ret = max (ret , vec[i].second - vec[i].first); last_max = vec[i].second; } } return ret; }};
0 0
- leetcode-Maximum Gap
- [LeetCode] Maximum Gap
- LeetCode Maximum Gap
- [leetCode] Maximum Gap
- leetcode 155: Maximum Gap
- LeetCode(164) Maximum Gap
- [LeetCode] Maximum Gap
- [leetcode 164] Maximum Gap
- [leetcode]Maximum Gap
- LeetCode - Maximum Gap 题解
- Maximum Gap|leetcode题解
- LeetCode[Sort]: Maximum Gap
- [LeetCode] Maximum Gap
- leetcode maximum gap
- [LeetCode]Maximum Gap
- LeetCode OJ Maximum Gap
- LeetCode Maximum Gap
- 【leetcode】 Maximum Gap
- 字符数组与字符指针
- StringBuilder、StringBuffer和String三者的联系和区别
- 【数据库】——SQL连接查询
- 引用类型的比较
- python中super用法研究
- leetcode Maximum Gap
- java中正则表达式使用
- php中的trait
- 通过自定义JAVA注解来理解JAVA注解
- linux命令系列三之解压-压缩
- Java集合小结
- Android绘图
- Java_IO_BufferedIntputStream_And_BufferedOutputStream
- 抽象工厂模式--简单的看法和使用