Fix incorrect indexes in two_sum.go (#1297)

pull/1303/head
huangjikun 7 months ago committed by GitHub
parent f616dac7da
commit 54ced94e4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -9,7 +9,7 @@ func twoSumBruteForce(nums []int, target int) []int {
size := len(nums) size := len(nums)
// 两层循环,时间复杂度为 O(n^2) // 两层循环,时间复杂度为 O(n^2)
for i := 0; i < size-1; i++ { for i := 0; i < size-1; i++ {
for j := i + 1; i < size; j++ { for j := i + 1; j < size; j++ {
if nums[i]+nums[j] == target { if nums[i]+nums[j] == target {
return []int{i, j} return []int{i, j}
} }

Loading…
Cancel
Save