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 8cce607

Browse files
committed
feat: add solutions to lcci problem: No.05.06
No.05.06.Convert Integer
1 parent 6d9d4fe commit 8cce607

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,32 @@ class Solution {
5353
}
5454
```
5555

56+
### **TypeScript**
57+
58+
```ts
59+
function convertInteger(A: number, B: number): number {
60+
let res = 0;
61+
while (A !== 0 || B !== 0) {
62+
if ((A & 1) !== (B & 1)) {
63+
res++;
64+
}
65+
A >>>= 1;
66+
B >>>= 1;
67+
}
68+
return res;
69+
}
70+
```
71+
72+
### **Rust**
73+
74+
```rust
75+
impl Solution {
76+
pub fn convert_integer(a: i32, b: i32) -> i32 {
77+
(a ^ b).count_ones() as i32
78+
}
79+
}
80+
```
81+
5682
### **...**
5783

5884
```

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,32 @@ class Solution {
5252
}
5353
```
5454

55+
### **TypeScript**
56+
57+
```ts
58+
function convertInteger(A: number, B: number): number {
59+
let res = 0;
60+
while (A !== 0 || B !== 0) {
61+
if ((A & 1) !== (B & 1)) {
62+
res++;
63+
}
64+
A >>>= 1;
65+
B >>>= 1;
66+
}
67+
return res;
68+
}
69+
```
70+
71+
### **Rust**
72+
73+
```rust
74+
impl Solution {
75+
pub fn convert_integer(a: i32, b: i32) -> i32 {
76+
(a ^ b).count_ones() as i32
77+
}
78+
}
79+
```
80+
5581
### **...**
5682

5783
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
impl Solution {
2+
pub fn convert_integer(a: i32, b: i32) -> i32 {
3+
(a ^ b).count_ones() as i32
4+
}
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function convertInteger(A: number, B: number): number {
2+
let res = 0;
3+
while (A !== 0 || B !== 0) {
4+
if ((A & 1) !== (B & 1)) {
5+
res++;
6+
}
7+
A >>>= 1;
8+
B >>>= 1;
9+
}
10+
return res;
11+
}

0 commit comments

Comments
(0)

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