
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.
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
Example:
这道最小栈跟原来的栈相比就是多了一个功能,可以返回该栈的最小值。使用两个栈来实现,一个栈来按顺序存储 push 进来的数据,另一个用来存出现过的最小值。代码如下:
C++ 解法一:
Java 解法一:
需要注意的是上面的 Java 解法中的 pop() 中,为什么不能用注释掉那两行的写法,博主之前也不太明白为啥不能对两个 stack 同时调用 peek() 函数来比较,如果是这种写法,那么不管 s1 和 s2 对栈顶元素是否相等,永远返回 false。这是为什么呢,这就要看 Java 对于peek的定义了,对于 peek() 函数的返回值并不是 int 类型,而是一个 Object 类型,这是一个基本的对象类型,如果直接用双等号 == 来比较的话,肯定不会返回 true,因为是两个不同的对象,所以一定要先将一个转为 int 型,然后再和另一个进行比较,这样才能得到想要的答案,这也是 Java 和 C++ 的一个重要的不同点吧。
那么下面再来看另一种解法,这种解法只用到了一个栈,还需要一个整型变量 min_val 来记录当前最小值,初始化为整型最大值,然后如果需要进栈的数字小于等于当前最小值 min_val,则将 min_val 压入栈,并且将 min_val 更新为当前数字。在出栈操作时,先将栈顶元素移出栈,再判断该元素是否和 min_val 相等,相等的话将 min_val 更新为新栈顶元素,再将新栈顶元素移出栈即可,参见代码如下:
C++ 解法二:
Java 解法二:
Github 同步地址:
#155
类似题目:
Sliding Window Maximum
Max Stack
参考资料:
https://leetcode.com/problems/min-stack/
https://leetcode.com/problems/min-stack/discuss/49014/java-accepted-solution-using-one-stack
https://leetcode.com/problems/min-stack/discuss/49016/c-using-two-stacks-quite-short-and-easy-to-understand
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: