首页 > 代码库 > LeetCode Maximum Gap

LeetCode Maximum Gap

class Solution {public:    int maximumGap(vector<int> &num) {        int len = num.size();        int gap = 0;        sort(num.begin(), num.end());        for (int i=0; i<len-1; i++) {            int cgap = num[i+1] - num[i];            if (cgap > gap) {                gap = cgap;            }        }        return gap;    }};

等会去看下discuss,找了一个使用基数排序的,发现比快排多了一倍的时间。

LeetCode Maximum Gap