Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sliding Window #47

Open
shanejix opened this issue Jul 22, 2021 · 0 comments
Open

Sliding Window #47

shanejix opened this issue Jul 22, 2021 · 0 comments

Comments

@shanejix
Copy link
Owner

什么是滑动窗口


- 实质就是一种数据结构-队列

- 滑动窗口的思想就是不断的移动窗口求得满足条件的解

- 如何移动呢?向队列的末端不断追加新的元素,不满足条件则队列首端的元素,直到满足要求,一直维持,求出解

滑动窗口适合求解的问题


- 固定长度序列之和的最值

- 不固定长度序列之和的最值

- 求和利用的是和累加性质,类似可以扩展为求叠加性质问题

解题模板

// 初始化滑动窗口左右指针
start , end = 0


while(end < len){

    // 叠加 end 下标对应元素

    // ...

    // 对窗口类元素校验
    if( ) or while(){
        // 叠减 start 下标对应元素 直到满足条件

        // ...

        start++
    }

    // 窗口右移
    end++
}

leetcode 题目

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant