package main
import "fmt"

func twoSum(nums []int, targ int) []int {
    prevMap := make(map[int]int)
    
    for i, v := range nums {
        diff := targ - v
        
        // same as: if (prevMap.containsKey(diff)) {}
        // variable 'exists' contains a boolean value
        if _, exists := prevMap[diff]; exists {
            return []int{prevMap[diff], i}
        }
        prevMap[v] = i
    }
    return []int{}
}

func main() {
    nums := []int {1, 2, 3}
    fmt.Println(nums)
    
    for target := 1; target < len(nums)+5; target++ {
        fmt.Println(twoSum(nums, target))
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: