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)
}
```