← All solutions

Contains Duplicates

March 03, 2025 • Go •array, hash table, sorting • easy

Fairly straight forward, I am getting the hang of the pattern behind simple hashmap.

Go Solution

func containsDuplicate(nums []int) bool {
    m := make(map[int]bool)

    for _, num := range nums {
        if _,k := m[num]; k {
            return true
        }

        m[num] = true
    }
    return false
}
LeetCode Problem Link