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

Sign up
Appearance settings

Commit 96ad384

Browse files
committed
feat:add without plus java solution
1 parent 614df8c commit 96ad384

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

‎lcci/17.01.Add Without Plus/README.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,18 @@
3434
<!-- 这里可写当前语言的特殊实现逻辑 -->
3535

3636
```java
37-
37+
class Solution {
38+
public int add(int a, int b) {
39+
int sum = 0, carry = 0;
40+
while (b != 0) {
41+
sum = a ^ b;
42+
carry = (a & b) << 1;
43+
a = sum;
44+
b = carry;
45+
}
46+
return a;
47+
}
48+
}
3849
```
3950

4051
### ...

‎lcci/17.01.Add Without Plus/README_EN.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,18 @@
4545
### Java
4646

4747
```java
48-
48+
class Solution {
49+
public int add(int a, int b) {
50+
int sum = 0, carry = 0;
51+
while (b != 0) {
52+
sum = a ^ b;
53+
carry = (a & b) << 1;
54+
a = sum;
55+
b = carry;
56+
}
57+
return a;
58+
}
59+
}
4960
```
5061

5162
### ...
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int add(int a, int b) {
3+
int sum = 0, carry = 0;
4+
while (b != 0) {
5+
sum = a ^ b;
6+
carry = (a & b) << 1;
7+
a = sum;
8+
b = carry;
9+
}
10+
return a;
11+
}
12+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /