## 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.

Hint:

``````    0 1 1

+   0 0 1

-----------

0 1 0

+   0 1 0

-----------

1 0 0``````

Code:

``````public class Solution {
public int getSum(int a, int b) {
int result = 0;

while (b != 0) {
int carry = (a & b) << 1;
a = a ^ b;
b = carry;
}
result = a;

return result;
}
}``````

### 初雪之音

Leetcode 371. Sum of Two Integers

SnailTyan
09/05
0
0

2016/12/12
16
0
Hackerrank，set、list时间复杂度问读

Problem Statement There is an array of n integers, and 2 disjoint sets of m integers each A and B. You like all integers in A and dislike all integers in B. Your initial happine......

zpengseu
2015/12/09
52
0

Given a positive integer, tell whether it is equal to the sum of four consecutive integers. Input A positive integer(<231), each case will be on a separate line. A zero (0) deno......

wwwmmm
2012/06/19
977
19
HDU - 1003 Max Sum

Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5......

Daybreaking
07/29
0
0

zookeeper配置与使用

23分钟前
1
0
spring源码阅读笔记（一）

ClassPathXmlApplicationContext 与 FileSystemXmlApplicationContext 用了这么久的框架，是时候搞一下源码了,一般最初接触spring 从以下步骤开始 创建一个bean类 并创建 ooxx.xml之类的spr...

NotFound403
47分钟前
2
0
MySQL主从配置

12月14日任务 17.1 MySQL主从介绍 17.2 准备工作 17.3 配置主 17.4 配置从 17.5 测试主从同步 MySQL主从介绍 MySQL主从又叫做Replication、AB复制。简单将就是A/B两个服务器做主从后，在A上写...

robertt15
49分钟前
8
0

22
0
Java 使用 gson 对 json 根据 key 键进行排序

yh32

4
0