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 c4b58b7

Browse files
committed
feat:add insert into bits,convert integer,exchange java solution
1 parent 96ad384 commit c4b58b7

File tree

9 files changed

+60
-6
lines changed

9 files changed

+60
-6
lines changed

‎lcci/05.01.Insert Into Bits/README.md‎

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

3636
```java
37-
37+
class Solution {
38+
public int insertBits(int N, int M, int i, int j) {
39+
for (int k = i; k <= j; k++) {
40+
N &= ~(1 << k);
41+
}
42+
return N ^ (M << i);
43+
}
44+
}
3845
```
3946

4047
### ...

‎lcci/05.01.Insert Into Bits/README_EN.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@
3131
### Java
3232

3333
```java
34-
34+
class Solution {
35+
public int insertBits(int N, int M, int i, int j) {
36+
for (int k = i; k <= j; k++) {
37+
N &= ~(1 << k);
38+
}
39+
return N ^ (M << i);
40+
}
41+
}
3542
```
3643

3744
### ...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution {
2+
public int insertBits(int N, int M, int i, int j) {
3+
for (int k = i; k <= j; k++) {
4+
N &= ~(1 << k);
5+
}
6+
return N ^ (M << i);
7+
}
8+
}

‎lcci/05.06.Convert Integer/README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
<!-- 这里可写当前语言的特殊实现逻辑 -->
4141

4242
```java
43-
43+
class Solution {
44+
public int convertInteger(int A, int B) {
45+
return Integer.bitCount(A ^ B);
46+
}
47+
}
4448
```
4549

4650
### ...

‎lcci/05.06.Convert Integer/README_EN.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@
5656
### Java
5757

5858
```java
59-
59+
class Solution {
60+
public int convertInteger(int A, int B) {
61+
return Integer.bitCount(A ^ B);
62+
}
63+
}
6064
```
6165

6266
### ...
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Solution {
2+
public int convertInteger(int A, int B) {
3+
return Integer.bitCount(A ^ B);
4+
}
5+
}

‎lcci/05.07.Exchange/README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@
4040
<!-- 这里可写当前语言的特殊实现逻辑 -->
4141

4242
```java
43-
43+
class Solution {
44+
public int exchangeBits(int num) {
45+
int t1 = num >> 1;
46+
int t2 = num << 1;
47+
return t1 & 0x55555555 | t2 & 0xaaaaaaaa;
48+
}
49+
}
4450
```
4551

4652
### ...

‎lcci/05.07.Exchange/README_EN.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@
5757
### Java
5858

5959
```java
60-
60+
class Solution {
61+
public int exchangeBits(int num) {
62+
int t1 = num >> 1;
63+
int t2 = num << 1;
64+
return t1 & 0x55555555 | t2 & 0xaaaaaaaa;
65+
}
66+
}
6167
```
6268

6369
### ...

‎lcci/05.07.Exchange/Solution.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution {
2+
public int exchangeBits(int num) {
3+
int t1 = num >> 1;
4+
int t2 = num << 1;
5+
return t1 & 0x55555555 | t2 & 0xaaaaaaaa;
6+
}
7+
}

0 commit comments

Comments
(0)

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