This commit is contained in:
krahets
2023-02-08 20:30:14 +08:00
parent 7156a5f832
commit 30ed83e5b1
10 changed files with 130 additions and 49 deletions

View File

@@ -1342,12 +1342,14 @@ $$
```swift title="space_complexity.swift"
/* 平方阶(递归实现) */
@discardableResult
func quadraticRecur(n: Int) -> Int {
if n <= 0 {
return 0
}
// 数组 nums 长度为 n, n-1, ..., 2, 1
let nums = Array(repeating: 0, count: n)
print("递归 n = \(n) 中的 nums 长度 = \(nums.count)")
return quadraticRecur(n: n - 1)
}
```

View File

@@ -161,6 +161,7 @@ comments: true
=== "Swift"
```swift title="leetcode_two_sum.swift"
/* 方法一:暴力枚举 */
func twoSumBruteForce(nums: [Int], target: Int) -> [Int] {
// 两层循环,时间复杂度 O(n^2)
for i in nums.indices.dropLast() {
@@ -344,6 +345,7 @@ comments: true
=== "Swift"
```swift title="leetcode_two_sum.swift"
/* 方法二:辅助哈希表 */
func twoSumHashTable(nums: [Int], target: Int) -> [Int] {
// 辅助哈希表,空间复杂度 O(n)
var dic: [Int: Int] = [:]

View File

@@ -903,7 +903,7 @@ $$
/* 常数阶 */
func constant(n: Int) -> Int {
var count = 0
let size = 100000
let size = 100_000
for _ in 0 ..< size {
count += 1
}