mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-19 03:55:50 +08:00
Update worst_best_time_complexity,
leetcode_two_sum
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
* Author: nuomi1 (nuomi1@qq.com)
|
||||
*/
|
||||
|
||||
/* 方法一:暴力枚举 */
|
||||
func twoSumBruteForce(nums: [Int], target: Int) -> [Int] {
|
||||
// 两层循环,时间复杂度 O(n^2)
|
||||
for i in nums.indices.dropLast() {
|
||||
@ -16,6 +17,7 @@ func twoSumBruteForce(nums: [Int], target: Int) -> [Int] {
|
||||
return [0]
|
||||
}
|
||||
|
||||
/* 方法二:辅助哈希表 */
|
||||
func twoSumHashTable(nums: [Int], target: Int) -> [Int] {
|
||||
// 辅助哈希表,空间复杂度 O(n)
|
||||
var dic: [Int: Int] = [:]
|
||||
|
Reference in New Issue
Block a user