Skip to content

Commit

Permalink
leetcode week3-1
Browse files Browse the repository at this point in the history
  • Loading branch information
bus710 committed Dec 25, 2024
1 parent 4c8b68f commit 64d6240
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions two-sum/bus710.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// O(n/2) as we only visit the half of the i*j

package hello

func twoSum(nums []int, target int) []int {
for i := range nums {
for j := i + 1; j < len(nums); j++ {
if (nums[i] + nums[j]) == target {
return []int{i, j}
}
}
}

return nil
}

0 comments on commit 64d6240

Please sign in to comment.