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