```
if (nums == null || k <= 0) {
return new int[0];
}
int[] res = new int[nums.length-k+1];
int resI = 0;
for (int i = k-1; i < nums.length; ++i) {
// get max of sliding window
int max = Integer.MIN_VALUE;
for (int j = i; j > i-k; j--) {
max = Math.max(max, nums[j]);
}
res[resI++]=max;
}
return res;
```