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 6b5f6b8

Browse files
authored
feat: add solutions to lc problem: No.2220 (doocs#3513)
1 parent 2157844 commit 6b5f6b8

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

‎solution/2200-2299/2220.Minimum Bit Flips to Convert Number/README.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,30 @@ int minBitFlips(int start, int goal) {
177177
178178
<!-- solution:end -->
179179
180+
<!-- solution:start -->
181+
182+
### Solution 2
183+
184+
<!-- tabs:start -->
185+
186+
#### TypeScript
187+
188+
```ts
189+
function minBitFlips(start: number, goal: number): number {
190+
return (start ^ goal).toString(2).replace(/0/g, '').length;
191+
}
192+
```
193+
194+
#### JavaScript
195+
196+
```js
197+
function minBitFlips(start, goal) {
198+
return (start ^ goal).toString(2).replace(/0/g, '').length;
199+
}
200+
```
201+
202+
<!-- tabs:end -->
203+
204+
<!-- solution:end -->
205+
180206
<!-- problem:end -->

‎solution/2200-2299/2220.Minimum Bit Flips to Convert Number/README_EN.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,30 @@ int minBitFlips(int start, int goal) {
175175
176176
<!-- solution:end -->
177177
178+
<!-- solution:start -->
179+
180+
### Solution 2
181+
182+
<!-- tabs:start -->
183+
184+
#### TypeScript
185+
186+
```ts
187+
function minBitFlips(start: number, goal: number): number {
188+
return (start ^ goal).toString(2).replace(/0/g, '').length;
189+
}
190+
```
191+
192+
#### JavaScript
193+
194+
```js
195+
function minBitFlips(start, goal) {
196+
return (start ^ goal).toString(2).replace(/0/g, '').length;
197+
}
198+
```
199+
200+
<!-- tabs:end -->
201+
202+
<!-- solution:end -->
203+
178204
<!-- problem:end -->
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function minBitFlips(start, goal) {
2+
return (start ^ goal).toString(2).replace(/0/g, '').length;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function minBitFlips(start: number, goal: number): number {
2+
return (start ^ goal).toString(2).replace(/0/g, '').length;
3+
}

0 commit comments

Comments
(0)

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