题解 | #滑动窗口的最大值#
滑动窗口的最大值
https://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param num int整型一维数组 * @param numLen int num数组长度 * @param size int整型 * @return int整型一维数组 * @return int* returnSize 返回数组行数 */ int* maxInWindows(int* nums, int numsSize, int k, int* returnSize ) { // write code here int start = 0, i = 0, len = 0; int max = 0; int* numsnew = NULL; if ((k <= 0) || (k > numsSize)) { * returnSize = 0; return NULL; } numsnew = (int*)malloc((numsSize - k + 1) * sizeof(int)); if (numsnew == NULL) { len = (numsSize - k + 1); printf("the malloc is failure\r\n"); return NULL; } *returnSize = numsSize - k + 1; for (i = 0; i < numsSize - k + 1; i++) { max = 0; for (start = i; start < i + k; start++) { if (max < nums[start]) { max = nums[start]; } } numsnew[i] = max; } return numsnew; }