栈和队列之生成窗口最大值数组
【摘要】 package com.chenyu.zuo.stackAndQueue; import java.util.LinkedList; /** * 题目:有一个整形数组,arr和一个大小为w的窗口从数组的最左边滑到最右边,窗口每次向右滑动一个位置。 * 例如数组[4,3,5,4,3,3,6,7],窗口的大小为3时; * [4 3 5] 4 3 3 6 7 窗口中最大值为5 * ...
-
package com.chenyu.zuo.stackAndQueue;
-
-
import java.util.LinkedList;
-
-
/**
-
* 题目:有一个整形数组,arr和一个大小为w的窗口从数组的最左边滑到最右边,窗口每次向右滑动一个位置。
-
* 例如数组[4,3,5,4,3,3,6,7],窗口的大小为3时;
-
* [4 3 5] 4 3 3 6 7 窗口中最大值为5
-
* 4[ 3 5 4] 3 3 6 7 窗口中最大值为5
-
* 4 3 [5 4 3] 3 6 7 窗口中最大值为5
-
* 4 3 5 [4 3 3 ]6 7 窗口中最大值为4
-
* 4 3 5 4 [3 3 6] 7 窗口中最大值为6
-
* 4 3 5 4 3 [3 6 7 ] 窗口中最大值为7
-
* 如果数组的长度为n,窗口大小为w,则一共产生n-w+1个窗口的最大值
-
* 请实现一个函数
-
* 输入:整数数组为arr,窗口大写为W。
-
* 输出:一个长度为n-w+1的数组res,res[i]表示每一种窗口状态下的最大值,以本题为例,结果应该返回{5,5,5,4,6,7}
-
*/
-
public class GetMaxWindow {
-
public static void main(String[] args) {
-
int [] arr1={4,3,5,4,3,3,6,7};
-
int w=3;
-
GetMaxWindow window=new GetMaxWindow();
-
arr1=window.getMaxWindow1(arr1, w);
-
for(int a:arr1){
-
System.out.println(a);
-
}
-
System.out.println("---------------------------------------");
-
i
文章来源: chenyu.blog.csdn.net,作者:chen.yu,版权归原作者所有,如需转载,请联系作者。
原文链接:chenyu.blog.csdn.net/article/details/50226531
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)