The maximum value of the sliding window for the offer (64) of the sword

Source: Internet
Author: User

Title Description

Given an array and the size of the sliding window, find the maximum value of the values in all the sliding windows. For example, if you enter the array {2,3,4,2,6,2,5,1} and the size of the sliding window 3, there are 6 sliding windows, their maximum value is {4,4,6,6,6,5}, and the sliding window for the array {2,3,4,2,6,2,5,1} has the following 6: {[ 2,3,4],2,6,2,5,1}, {2,[3,4,2],6,2,5,1}, {2,3,[4,2,6],2,5,1}, {2,3,4,[2,6,2],5,1}, {2,3,4,2,[6,2,5],1}, {2,3,4,2,6,[ 2,5,1]}.

Code:

<span style= "color: #33cc00;" >import java.util.*;p Ublic class Solution {public    arraylist<integer> maxinwindows (int [] num, int size) { c1/>arraylist<integer> list  = new arraylist<integer> ();        if (size>num.length| | size==0)            return list;        for (int i = 0;i<=num.length-size;i++) {            int max = num[i];            for (int j = i+1;j<i+size;j++) {                if (Num[j]>max) {                    max = num[j];                }            }            List.add (max);        }        return list;    }} </span>


The maximum value of the sliding window for the offer (64) of the sword

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.