In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces leetcode how to achieve sliding window, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
The basic skill of sliding window is to maintain a sliding window and move the left and right pointer of the window to make the window meet certain conditions. the key is how to deal with the places where the window meets the conditions to make the algorithm more efficient.
The number of maximum consecutive ones
Given an array A consisting of several zeros and ones, we can change the values of K from 0 to 1 at most.
Returns the length of the longest (consecutive) subarray containing only 1.
Example 1:
Input: a = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], K = 2.
Output: 6
Explanation:
[1,1,1,0,0,1,1,1,1,1,1]
The bold number is flipped from 0 to 1, and the longest subarray is 6.
Example 2:
Input: a = [0re0pence1reparent1jor0re0re0reie1jjjjjjjjjjjjjjjjng.0jpg], K = 3
Output: 10
Explanation:
[0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]
The bold number is flipped from 0 to 1, and the longest subarray is 10.
Ideas for solving the problem:
1. The main point of this question is not the length of the sliding window, but that to maintain the number of zeros in the window K, you need to move the left pointer to subtract the number of zeros by 1.
B,sum
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.