mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-30 16:53:53 +00:00
Update 65. 不用加减乘除做加法.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
## 题目链接
|
||||
|
||||
[NowCoder](https://www.nowcoder.com/practice/59ac416b4b944300b617d4f7f111b215?tpId=13&tqId=11201&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
|
||||
[Leetcode](https://leetcode.cn/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/)
|
||||
|
||||
## 题目描述
|
||||
|
||||
@@ -15,7 +15,7 @@ a ^ b 表示没有考虑进位的情况下两数的和,(a & b) \<\< 1 就是
|
||||
递归会终止的原因是 (a & b) \<\< 1 最右边会多一个 0,那么继续递归,进位最右边的 0 会慢慢增多,最后进位会变为 0,递归终止。
|
||||
|
||||
```java
|
||||
public int Add(int a, int b) {
|
||||
return b == 0 ? a : Add(a ^ b, (a & b) << 1);
|
||||
public int encryptionCalculate(int dataA, int dataB) {
|
||||
return dataB == 0 ? dataA : encryptionCalculate(dataA ^ dataB, (dataA & dataB) << 1);
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user