Leetcode218: Maximum Gap
2016-01-07 15:22
302 查看
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.
Try to solve it in linear time/space.
Return 0 if the array contains less than 2 elements.
You may assume all elements in the array are non-negative integers and fit in the 32-bit signed integer range.
桶排序,未完待续。
Try to solve it in linear time/space.
Return 0 if the array contains less than 2 elements.
You may assume all elements in the array are non-negative integers and fit in the 32-bit signed integer range.
class Solution { public: int maximumGap(vector<int>& nums) { int n = nums.size(); if(n < 2) return 0; sort(nums.begin(), nums.end()); int res=0; for(int i = 1; i < n; i++) res = max(res, nums[i]-nums[i-1]); return res; } };
桶排序,未完待续。
相关文章推荐
- “约定优于配置”与Magento改造尝试二之布局xml文件加载
- 人工智能学习笔记(一)命题逻辑
- 一个手握安兔兔,一个执掌鲁大师,周鸿祎雷军这场仗谁能赢?
- 开发环境、生产环境、测试环境的基本理解和区别
- numpy安装
- 1.7作业
- web 应用的部署
- BZOJ 1079: [SCOI2008]着色方案 DP
- 9.配置zabbix网络发现
- 关于SVM一篇比较全介绍的博文 [复制链接]
- 树莓派B+ GPIO定义
- 机器学习与数据挖掘网上资源搜罗——良心推荐
- 图像处理与机器视觉网络资源收罗——倾心大放送
- 百度上传控件webuploader的上传与修改,Java版本
- Java虚拟机之内存
- WebVeiw的属性大全
- 7.UIScrollView的基本使用
- ubuntu中测试进程的处理器亲和性和vCPU的绑定
- java26.线程------优先级
- dx 工具的使用