LeetCode 371 Sum of Two Integers (位运算)
2016-09-23 09:01
453 查看
Calculate the sum of two integers a and
b, but you are not allowed to use the operator
Example:
Given a = 1 and b = 2, return 3.
Credits:
Special thanks to
@fujiaozhu for adding this problem and creating all test cases.
题目链接:https://leetcode.com/problems/sum-of-two-integers/
题目分析:见前一篇博文
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.
题目链接:https://leetcode.com/problems/sum-of-two-integers/
题目分析:见前一篇博文
public class Solution { 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); } }
相关文章推荐
- C++ —— C++高手之路
- 创建线程的方法
- 颠覆传统app格局的微信小程序来了:微信小程序开发环境搭建
- 3、RIOT操作系统的文件结构和CC2538在RIOT中的相关基础介绍
- opencv-ios开发笔记11 亮度和色温调节
- Java VisualVM分析JVM内存溢出
- 属性过滤选择器
- 伪静态,防盗链怎么开启
- Node学习思维导图
- Decompiled .class file,bytecode version:52.0(Java 8) Source for 'Android API 24 Platform' not found
- php数据类型的判断及转换
- 申请阿里云的ECS服务器
- Missing Number
- 数据库的三大范式
- 五最好的应聘者可以问问题
- 常见的Java 问题排查方法
- 第二次作业及总结——数据类型和运算符
- Python Web 开发学习 - 学习笔记(1)- Python特性
- 第五周-C语言 简单数列的求和
- shell 的几个数据处理命令 管道命令