
Divide array into arrays with max difference
정렬하고 최소값 최대값 차이가 k이하이면 된다. 굉장히 쉬운문제
배열을 정렬하고 3개씩 방문하며 3개에서 첫째 값과 셋째 값의 차이가 k 이하이면 3개의 배열을 저장하고 아니면 함수를 종료하고 빈찬합을 준다



import java.util.*;
class Solution {
public int[][] divideArray(int[] nums, int k) {
Arrays.sort(nums);
int size = nums.length / 3;
int[][] answer = new int[size][];
for(int i = 0; i < size; i ++){
int first = nums[i * 3 + 0];
int second = nums[i * 3 + 1];
int third = nums[i * 3 + 2];
if (third - first > k){
return new int[0][];
}
answer[i] = new int[]{first,second,third};
}
return answer;
}
}