Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
29 lines (26 loc) · 635 Bytes

File metadata and controls

29 lines (26 loc) · 635 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.lintcode;
/**
* 1. A + B 问题
* 给出两个整数a和b, 求他们的和, 但不能使用 + 等数学运算符。
*
* 挑战:显然你可以直接 return a + b,但是你是否可以挑战一下不这样做?
*/
public class Solution1 {
/**
* @param a: An integer
* @param b: An integer
* @return: The sum of a and b
*/
public int aplusb(int a, int b) {
// write your code here
if (a == 0) {
return b;
}
if (b == 0){
return a;
}
int c = a ^ b;
int d = (a & b)<<1;
return aplusb(c, d);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.