
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.
Calculate the sum of two integers a and b , but you are not allowed to use the operator
+
and-
.Example 1:
Example 2:
Credits:
Special thanks to @fujiaozhu for adding this problem and creating all test cases.
这道题是 CareerCup 上的一道原题,可参见博主之前的博客 18.1 Add Two Numbers。这里让实现两数相加,但是不能用加号或者其他什么数学运算符号,那么只能回归计算机运算的本质,位操作 Bit Manipulation,在做加法运算的时候,每位相加之后可能会有进位 Carry 产生,然后在下一位计算时需要加上进位一起运算,那么能不能将两部分拆开呢,来看一个例子 759+674
1. 如果不考虑进位,可以得到 323
2. 如果只考虑进位,可以得到 1110
3. 把上面两个数字假期 323+1110=1433 就是最终结果了
然后进一步分析,如果得到上面的第一第二种情况,在二进制下来看,不考虑进位的加,0+0=0,0+1=1, 1+0=1,1+1=0,这就是异或的运算规则,如果只考虑进位的加 0+0=0, 0+1=0, 1+0=0, 1+1=1,而这其实这就是'与'的运算,而第三步在将两者相加时,再递归调用这个算法,终止条件是当进位为0时,直接返回第一步的结果。一切都是如此的美好,突然有一天,博主的所有方法都无法通过 OJ 了,不知为何,原因不明。在热心网友 GGGGITFK 的提示下,终于知道了错误的原因:
runtime error: left shift of negative value -2147483648,对INT_MIN左移位。
就是 LeetCode 自己的编译器比较 strict,不能对负数进行左移,就是说最高位符号位必须要为0,才能左移(此处应有尼克杨问号脸?!),好吧,你赢了。那么在a和b相 '与' 之后,再'与'上一个最高位为0,其余位都为1的数 0x7fffffff,这样可以强制将最高位清零,然后再进行左移,终于,世界清静了,参见代码如下:
解法一:
上面的解法可以精简到一行,哈哈,叼不叼?
解法二:
也可以写成迭代的样子,思路都是一样的~
解法三:
Github 同步地址:
#371
类似题目:
Add Two Numbers
参考资料:
https://leetcode.com/problems/sum-of-two-integers/
https://leetcode.com/problems/sum-of-two-integers/discuss/84290/Java-simple-easy-understand-solution-with-explanation
https://leetcode.com/problems/sum-of-two-integers/discuss/84278/A-summary%3A-how-to-use-bit-manipulation-to-solve-problems-easily-and-efficiently
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: