Skip to content

feat:add without plus java solution #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat:add without plus java solution
  • Loading branch information
J-Cod3r committed Jun 21, 2020
commit 96ad3847869c22ea3836af828b7642aac1f45e43
13 changes: 12 additions & 1 deletion lcci/17.01.Add Without Plus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@
<!-- 这里可写当前语言的特殊实现逻辑 -->

```java

class Solution {
public int add(int a, int b) {
int sum = 0, carry = 0;
while (b != 0) {
sum = a ^ b;
carry = (a & b) << 1;
a = sum;
b = carry;
}
return a;
}
}
```

### ...
Expand Down
13 changes: 12 additions & 1 deletion lcci/17.01.Add Without Plus/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,18 @@
### Java

```java

class Solution {
public int add(int a, int b) {
int sum = 0, carry = 0;
while (b != 0) {
sum = a ^ b;
carry = (a & b) << 1;
a = sum;
b = carry;
}
return a;
}
}
```

### ...
Expand Down
12 changes: 12 additions & 0 deletions lcci/17.01.Add Without Plus/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
public int add(int a, int b) {
int sum = 0, carry = 0;
while (b != 0) {
sum = a ^ b;
carry = (a & b) << 1;
a = sum;
b = carry;
}
return a;
}
}