
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.
The Fibonacci numbers, commonly denoted
F(n)
form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from0
and1
. That is,Given
N
, calculateF(N)
.Example 1:
Example 2:
Example 3:
Note:
0 ≤
N
≤ 30.这道题是关于斐波那契数列的,这个数列想必我们都听说过,简而言之,除了前两个数字之外,每个数字等于前两个数字之和。举个生动的例子,大学食堂里今天的汤是昨天的汤加上前天的汤。哈哈,是不是瞬间记牢了。题目没让返回整个数列,而是直接让返回位置为N的数字。那么还是要构建整个斐波那契数组,才能知道位置N上的数字。像这种有规律有 pattern 的数组,最简单的方法就是使用递归啦,先把不合规律的前两个数字处理了,然后直接对 N-1 和 N-2 调用递归,并相加返回即可,参见代码如下:
解法一:
上面的写法虽然简单,但是并不高效,因为有大量的重复计算,我们希望每个值只计算一次,所以可以使用动态规划 Dynamic Programming 来做,建立一个大小为 N+1 的 dp 数组,其中 dp[i] 为位置i上的数字,先初始化前两个分别为0和1,然后就可以开始更新整个数组了,状态转移方程就是斐波那契数组的性质,最后返回 dp[N] 即可,参见代码如下:
解法二:
我们可以对上面解法进行空间上的进一步优化,由于当前数字只跟前两个数字有关,所以不需要保存整个数组,而是只需要保存前两个数字就行了,前一个数字用b表示,再前面的用a表示。a和b分别初始化为0和1,代表数组的前两个数字。然后从位置2开始更新,先算出a和b的和 sum,然后a更新为b,b更新为 sum。最后返回b即可,参见代码如下:
解法三:
给下面的这种解法跪了,直接 hardcode 了所有N范围内的斐波那契数字,然后直接返回,这尼玛诸葛孔明的棺材板快压不住了。。。我从未见过如此。。。
解法四:
Github 同步地址:
#509
类似题目:
Split Array into Fibonacci Sequence
Length of Longest Fibonacci Subsequence
参考资料:
https://leetcode.com/problems/fibonacci-number/
https://leetcode.com/problems/fibonacci-number/discuss/215992/Java-Solutions
https://leetcode.com/problems/fibonacci-number/discuss/216245/Java-O(1)-time
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: