mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-05 11:41:22 +08:00
build
This commit is contained in:
@@ -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)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -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] = [:]
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user