371. Sum of Two Integers
来源:互联网 发布:中日海军对比2017知乎 编辑:程序博客网 时间:2024/06/05 13:13
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.
Credits:
Special thanks to @fujiaozhu for adding this problem and creating all test cases.
public class Solution { public int getSum(int a, int b) { if (a == 0) { return b; } if (b == 0) { return a; } while (b != 0) { int carry = a & b; a = a ^ b; b = carry << 1; } return a; }}
0 0
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 机器学习基础 第五章 降维算法
- Linux Kernel 4.9中TCP BBR算法的科普解释
- 增强学习系列之(一):增强学习介绍
- 共同学习Java源代码-数据结构-TreeSet(一)
- 策略模式和Spring的结合在项目中的应用
- 371. Sum of Two Integers
- Codeforces 681C Heap Operation 【模拟】【堆】
- cf 341C (容斥原理)
- Win10 独立音量调整
- 3.1入门模拟B1008. 数组元素循环右移问题 (20)
- Javascript异步编程的4种方法
- 机器学习基础 第六章 模型选择
- 为什么要重写hashcode() 方法
- java.io.Serializable浅析