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 2b94218

Browse files
feat: add swift implementation to lcci problem: No.05.01 (doocs#2665)
1 parent 9d76d65 commit 2b94218

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ function insertBits(N: number, M: number, i: number, j: number): number {
8181
}
8282
```
8383

84+
```swift
85+
class Solution {
86+
func insertBits(_ N: Int, _ M: Int, _ i: Int, _ j: Int) -> Int {
87+
var result = N
88+
89+
for k in i...j {
90+
result &= ~(1 << k)
91+
}
92+
93+
return result | (M << i)
94+
}
95+
}
96+
```
97+
8498
<!-- tabs:end -->
8599

86100
<!-- end -->

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ function insertBits(N: number, M: number, i: number, j: number): number {
8181
}
8282
```
8383

84+
```swift
85+
class Solution {
86+
func insertBits(_ N: Int, _ M: Int, _ i: Int, _ j: Int) -> Int {
87+
var result = N
88+
89+
for k in i...j {
90+
result &= ~(1 << k)
91+
}
92+
93+
return result | (M << i)
94+
}
95+
}
96+
```
97+
8498
<!-- tabs:end -->
8599

86100
<!-- end -->
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
func insertBits(_ N: Int, _ M: Int, _ i: Int, _ j: Int) -> Int {
3+
var result = N
4+
5+
for k in i...j {
6+
result &= ~(1 << k)
7+
}
8+
9+
return result | (M << i)
10+
}
11+
}

0 commit comments

Comments
(0)

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