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
@@ -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] = [:]