Skip to content

Commit 805d2fc

Browse files
authored
feat: add swift implementation to lcof2 problem: No.068 (#3182)
1 parent 31290df commit 805d2fc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lcof2/剑指 Offer II 068. 查找插入位置/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,26 @@ var searchInsert = function (nums, target) {
170170
};
171171
```
172172

173+
#### Swift
174+
175+
```swift
176+
class Solution {
177+
func searchInsert(_ nums: [Int], _ target: Int) -> Int {
178+
var left = 0
179+
var right = nums.count
180+
while left < right {
181+
let mid = (left + right) / 2
182+
if nums[mid] >= target {
183+
right = mid
184+
} else {
185+
left = mid + 1
186+
}
187+
}
188+
return left
189+
}
190+
}
191+
```
192+
173193
<!-- tabs:end -->
174194

175195
<!-- solution:end -->

lcof2/剑指 Offer II 068. 查找插入位置/Solution.swift

Whitespace-only changes.

0 commit comments

Comments
 (0)