
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 positive integer
N
, find and return the longest distance between two consecutive 1's in the binary representation ofN
.If there aren't two consecutive 1's, return 0.
Example 1:
Example 2:
Example 3:
Example 4:
Note:
1 <= N <= 10^9
这道题给了我们一个正整数,问其二进制表示数中两个 '1' 之间的最大距离是多少。比如整数 22 的二进制为 10110,那么可以看出前两个 '1' 之间的距离最大,所以返回2即可。其实这道题的考察点就是如何按位取数,对一个二进制数直接与 '1',就可以提取出最低位,然后和0比较大小,就知道最低位是0还是1了。当然为了每一位的是0还是1,一般有两种处理方法,一种是直接将原数字右移一位,则之前的最低位被移除了,再和 '1' 相与即可,直到原数字变为0停止。另一种方法是直接右移固定的位数再与 '1',因为整型数只有 32 位,所以可以直接取出任意位上的数字。那么既然要求两个 '1' 之间的最大距离,那么只要关心 '1' 的位置即可,一种比较直接的思路就是先遍历一遍各位上的数字,将所有 '1' 的坐标位置都保存到一个数组 pos 之中,然后再遍历这个 pos 数组,计算相邻两个数字的差,即两个 '1' 之间的距离,更新结果 res 即可得到最大距离,参见代码如下:
解法一:
我们也可以只用一个循环来完成,而且不用 pos 数组,只用一个变量 last 来记录上一个遍历到的 '1' 的位置,初始化为 -1。那么在遍历的过程中,若遇到了 '1',则判断 last 是否大于等于0,是的话则表示之前已经遇到了 '1',那么当前位置i减去 last,即为两个 '1' 之间的距离,用来更新结果 res,然后再更新 last 为当前位置i,继续遍历即可,参见代码如下:
解法二:
Github 同步地址:
#868
参考资料:
https://leetcode.com/problems/binary-gap/
https://leetcode.com/problems/binary-gap/discuss/149945/Simple-Java-(10-ms)
https://leetcode.com/problems/binary-gap/discuss/149835/C%2B%2BJavaPython-Dividing-by-2
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: