Add Swift language blocks to the docs.

This commit is contained in:
Yudong Jin
2023-01-08 19:41:05 +08:00
parent 3ba37dba3a
commit 73e3452838
22 changed files with 414 additions and 70 deletions

View File

@ -4,7 +4,7 @@
* Author: nuomi1 (nuomi1@qq.com)
*/
//
/* */
func randomAccess(nums: [Int]) -> Int {
// [0, nums.count)
let randomIndex = nums.indices.randomElement()!
@ -13,7 +13,7 @@ func randomAccess(nums: [Int]) -> Int {
return randomNum
}
//
/* */
func extend(nums: [Int], enlarge: Int) -> [Int] {
//
var res = Array(repeating: 0, count: nums.count + enlarge)
@ -25,7 +25,7 @@ func extend(nums: [Int], enlarge: Int) -> [Int] {
return res
}
// index num
/* index num */
func insert(nums: inout [Int], num: Int, index: Int) {
// index
for i in sequence(first: nums.count - 1, next: { $0 > index + 1 ? $0 - 1 : nil }) {
@ -35,7 +35,7 @@ func insert(nums: inout [Int], num: Int, index: Int) {
nums[index] = num
}
// index
/* index */
func remove(nums: inout [Int], index: Int) {
let count = nums.count
// index
@ -44,7 +44,7 @@ func remove(nums: inout [Int], index: Int) {
}
}
//
/* */
func traverse(nums: [Int]) {
var count = 0
//
@ -57,7 +57,7 @@ func traverse(nums: [Int]) {
}
}
//
/* */
func find(nums: [Int], target: Int) -> Int {
for i in nums.indices {
if nums[i] == target {