题解 | #滑动窗口的最大值#
滑动窗口的最大值
https://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
int getMaxInWindows(int *w, int wSize) {// 获取窗口数组中的最大值 int i = 0; int max = w[0]; for(i=1;i<wSize;i++) { if(w[i]>max) { max = w[i]; } } return max; } int* maxInWindows(int* num, int numLen, int size, int* returnSize ) { if(numLen==0 || numLen < size || size == 0) { *returnSize = 0; return NULL; } int *arr = (int *)malloc(sizeof(int)*(numLen-size+1)); int index = 0; for(index=0;(index+size-1)<numLen;index++) { arr[index] = getMaxInWindows(num+index, size); } *returnSize = numLen-size+1; return arr; }