
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.
We are given an array
asteroids
of integers representing asteroids in a row.For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.
Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.
Example 1:
Example 2:
Example 3:
Example 4:
Note:
asteroids
will be at most10000
.[-1000, 1000].
.这道题用一个数组来模拟行星碰撞,正数代表行星向右移动,负数表示向左移动,绝对值大小表示行星的质量,如果两个相邻的行星相向移动会碰撞,质量大的行星会完好无损的保存,质量小的就会灰飞烟灭。那么博主最开始想的方法就是按照题目要求来一个一个的处理,我们先把给定的数组放到结果res中,然后进行while循环,如果此时结果res中的数字个数小于等于1个,直接返回即可,没有可碰撞的了。否则我们建立一个临时数组t,把结果res中的首元素放到t中,然后从第二个数字开始遍历结果res,如果此时t为空了,或者当前数字大于0而t数组最后一个数字小于0(此时两个行星向相反方向运动,不会相撞),或者两个数字的符号相同(此时两个行星向同一个方向运动,不会相撞),这三种情况下都把当前数字res[i]加到数组t中;那么剩下的情况就是两个行星相向运动了,如果两个数字相加等于0,则说明两个行星质量相同,且相向运动,则一起消失,我们将数组t中最后一个数字移除;如果当前数字小于0,且两个数字相加小于0,那么此时相撞后会留下质量大的行星,我们将数组t的最后一个数字赋值为res[i]即可。for循环之和,如果数组t和结果res的大小相等,说明此时状态已经稳定了,我们直接break,否则就把数组t赋值给结果res并继续循环,参见代码如下:
解法一:
实际上我们可以写的更加简洁一些,我们遍历所有的数字,如果当前数字是正数的话,我们直接加入结果res;否则我们遇到的都是负数,如果结果res为空,或者结果res的最后一个数字小于0(此时两个行星同时向左运动),直接将当前数字加入结果res;如果结果res的最后一个数字(此时为正数)小于当前数字的绝对值,说明碰撞后消失了,那么我们将i自减一个,然后将res最后一个数字移除,这样下次遍历的时候还是这个质量大的行星。如果两个质量相等,那么直接移除res最后一个数字,此时两个行星都消失了,参见代码如下:
解法二:
类似题目:
Can Place Flowers
参考资料:
https://discuss.leetcode.com/topic/112034/java-c-clean-code
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: