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

239. 滑动窗口最大值 #35

Open
GpingFeng opened this issue Dec 26, 2020 · 1 comment
Open

239. 滑动窗口最大值 #35

GpingFeng opened this issue Dec 26, 2020 · 1 comment

Comments

@GpingFeng
Copy link
Owner

239. 滑动窗口最大值

解题思路——暴力法

var maxSlidingWindow = function(nums, k) {
  let res = [];
  for (let i = k - 1; i < nums.length; i++) {
    let max = -Infinity;
    for (let j=i-k+1; j < i+1; j++) {
       max = Math.max(max, nums[j]);
    }
    res.push(max);
  }
  return res;
};

复杂度分析

  • 时间复杂度——O(n^2)
  • 空间复杂度——O(n)
@GpingFeng
Copy link
Owner Author

TODO:双端队列以及动态规划

@GpingFeng GpingFeng added Hard and removed Easy labels Dec 26, 2020
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