
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 circular array C of integers represented by
A
, find the maximum possible sum of a non-empty subarray of C.Here, a circular array means the end of the array connects to the beginning of the array. (Formally,
C[i] = A[i]
when0 <= i < A.length
, andC[i+A.length] = C[i]
wheni >= 0
.)Also, a subarray may only include each element of the fixed buffer
A
at most once. (Formally, for a subarrayC[i], C[i+1], ..., C[j]
, there does not existi <= k1, k2 <= j
withk1 % A.length = k2 % A.length
.)Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Note:
-30000 <= A[i] <= 30000
1 <= A.length <= 30000
这道题让求环形子数组的最大和,对于环形数组,我们应该并不陌生,之前也做过类似的题目 Circular Array Loop,就是说遍历到末尾之后又能回到开头继续遍历。假如没有环形数组这一个条件,其实就跟之前那道 Maximum Subarray 一样,解法比较直接易懂。这里加上了环形数组的条件,难度就增加了一些,需要用到一些 trick。既然是子数组,则意味着必须是相连的数字,而由于环形数组的存在,说明可以首尾相连,这样的话,最长子数组的范围可以有两种情况,一种是正常的,数组中的某一段子数组,另一种是分为两段的,即首尾相连的,可以参见 大神 lee215 的帖子 中的示意图。对于第一种情况,其实就是之前那道题 Maximum Subarray 的做法,对于第二种情况,需要转换一下思路,除去两段的部分,中间剩的那段子数组其实是和最小的子数组,只要用之前的方法求出子数组的最小和,用数组总数字和一减,同样可以得到最大和。两种情况的最大和都要计算出来,取二者之间的较大值才是真正的和最大的子数组。但是这里有个 corner case 需要注意一下,假如数组中全是负数,那么和最小的子数组就是原数组本身,则求出的差值是0,而第一种情况求出的和最大的子数组也应该是负数,那么二者一比较,返回0就不对了,所以这种特殊情况需要单独处理一下,参见代码如下:
Github 同步地址:
#918
类似题目:
Maximum Subarray
Circular Array Loop
参考资料:
https://leetcode.com/problems/maximum-sum-circular-subarray/
https://leetcode.com/problems/maximum-sum-circular-subarray/discuss/178422/One-Pass
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: