1 Star 0 Fork 0

徐长贺/Leetcode

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
_371.java 627 Bytes
一键复制 编辑 原始数据 按行查看 历史
Fisher Coder 提交于 2019-02-08 23:58 +08:00 . refactor 371
package com.fishercoder.solutions;
/**
* 371. Sum of Two Integers
*
* Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.
Example:
Given a = 1 and b = 2, return 3.
*/
public class _371 {
public static class Solution1 {
/** reference: http://stackoverflow.com/questions/9070937/adding-two-numbers-without-operator-clarification */
public int getSum(int a, int b) {
if (b == 0) {
return a;
}
int sum = a ^ b;
int carry = (a & b) << 1;
return getSum(sum, carry);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/isulong/Leetcode.git
git@gitee.com:isulong/Leetcode.git
isulong
Leetcode
Leetcode
master

搜索帮助