leetcode+ 桶排序

点击打开链接
//没看懂
class Solution {
public:
    int maximumGap(vector& nums) {
        if(nums.empty()) return 0;
        int mx = INT_MIN, mn = INT_MAX, n=nums.size();
        for(int d: nums){
            mx = max(mx, d);
            mn = min(mn, d);
        }
        int size = (mx - mn)/n + 1;
        int bucket_nums = (mx - mn) / size  + 1;
        vector bucket_min(bucket_nums, INT_MAX);
        vector bucket_max(bucket_nums, INT_MIN);
        set s;
        for(int d: nums){
            int idx = (d-mn) / size;
            bucket_min[idx] = min(bucket_min[idx], d);
            bucket_max[idx] = max(bucket_max[idx], d);
            s.insert(idx);
        }
        int pre = 0, res = 0;
        for(int i=1; i
leetcode+ 桶排序_第1张图片

你可能感兴趣的:(Leetcode)