Fix incorrect indexes in two_sum.go (#1297)

This commit is contained in:
huangjikun 2024-04-22 02:28:54 +08:00 committed by GitHub
parent f616dac7da
commit 54ced94e4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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}
} }