leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2294.cpp (285B)


      1 class Solution {
      2   public:
      3     int partitionArray(vector<int> &nums, int k) {
      4         sort(begin(nums), end(nums));
      5 
      6         int res = 1, j = 0;
      7         for (int i = 1; i < nums.size(); i++) {
      8             if (nums[i] - nums[j] > k) j = i, res++;
      9         }
     10         return res;
     11     }
     12 };