
Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
History is littered with hundreds of conflicts over the future of a community, group, location or business that were "resolved" when one of the parties stepped ahead and destroyed what was there. With the original point of contention destroyed, the debates would fall to the wayside. Archive Team believes that by duplicated condemned data, the conversation and debate can continue, as well as the richness and insight gained by keeping the materials. Our projects have ranged in size from a single volunteer downloading the data to a small-but-critical site, to over 100 volunteers stepping forward to acquire terabytes of user-created data to save for future generations.
The main site for Archive Team is at archiveteam.org and contains up to the date information on various projects, manifestos, plans and walkthroughs.
This collection contains the output of many Archive Team projects, both ongoing and completed. Thanks to the generous providing of disk space by the Internet Archive, multi-terabyte datasets can be made available, as well as in use by the Wayback Machine, providing a path back to lost websites and work.
Our collection has grown to the point of having sub-collections for the type of data we acquire. If you are seeking to browse the contents of these collections, the Wayback Machine is the best first stop. Otherwise, you are free to dig into the stacks to see what you may find.
The Archive Team Panic Downloads are full pulldowns of currently extant websites, meant to serve as emergency backups for needed sites that are in danger of closing, or which will be missed dearly if suddenly lost due to hard drive crashes or server failures.
Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at most one 0.
Example 1:
Note:
0
and1
.Follow up:
What if the input numbers come in one by one as an infinite stream? In other words, you can't store all numbers coming from the stream as it's too large to hold in memory. Could you solve it efficiently?
这道题在之前那道题 Max Consecutive Ones 的基础上加了一个条件,说有一次将0翻转成1的机会,问此时最大连续1的个数,再看看 follow up 中的说明,很明显只遍历一次数组,那我们想,肯定需要用一个变量 cnt 来记录连续1的个数吧,那么当遇到了0的时候怎么处理呢,因为有一次0变1的机会,所以遇到0了还是要累加 cnt,然后此时需要用另外一个变量 cur 来保存当前 cnt 的值,然后 cnt 重置为0,以便于让 cnt 一直用来统计纯连续1的个数,然后我们每次都用用 cnt+cur 来更新结果 res,参见代码如下:
解法一:
上面的方法有局限性,如果题目中说能翻转k次怎么办呢,最好用一个通解来处理这类问题。可以维护一个窗口 [left,right] 来容纳至少k个0。当遇到了0,就累加 zero 的个数,然后判断如果此时0的个数大于k,则右移左边界left,如果移除掉的 nums[left] 为0,那么 zero 自减1。如果不大于k,则用窗口中数字的个数来更新 res,参见代码如下:
解法二:
上面那种方法对于 follow up 中的情况无法使用,因为 nums[left] 需要访问之前的数字。我们可以将遇到的0的位置全都保存下来,这样需要移动 left 的时候就知道移到哪里了:
解法三:
Github 同步地址:
#487
类似题目:
Max Consecutive Ones
Max Consecutive Ones III
参考资料:
https://leetcode.com/problems/max-consecutive-ones-ii/
https://discuss.leetcode.com/topic/75439/java-concise-o-n-time-o-1-space
https://discuss.leetcode.com/topic/75445/java-clean-solution-easily-extensible-to-flipping-k-zero-and-follow-up-handled
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: