Contains Duplicate

ID: 217; easy

Solution 1

func containsDuplicate(nums []int) bool {
    m := make(map[int]int)
    for _, v := range nums {
        m[v]++
        if m[v] >= 2 {
            return true
        }
    }
    return false
}

Solution 2

func containsDuplicate(nums []int) bool {
    m := make(map[int]bool, len(nums))
	for _, n := range nums {
		if _, found := m[n]; found {
			return true
		}
		m[n] = true
	}
	return false
}

Booleans take less space

Last updated