Count the number of discrete values in a slice I'm using this right now to count the number of discrete values in a given []string. Is there a faster way to do this?

func CountDiscrete(x []string) int {
    discrete := 0

    for i,xi := range x {
        is_discrete := true
        for j,xj := range x {
            if i != j {
                if xi == xj {
                    is_discrete = false
                    break
                }
            }
        }

        if is_discrete {
            discrete = discrete + 1
        }
    }

    return discrete
}
Code review:
1. Use  discrete++ instead of discrete = discrete + 1
2. Use if i != j &amp;&amp; xi == xj instead of  

if i != j {
    if xi == xj {
        is_discrete = false
        break
     }
}



Don't use underscores in Go names: is_discrete, simply use discrete or isDiscrete.
You may use slice ...string instead of slice []string like the following code:


// O(n**2)
func distincts(x ...string) int {
    result := 0
    for i, xi := range x {
        unique := 1
        for j, xj := range x {
            if i != j &amp;&amp; xi == xj {
                unique = 0
                break
            }
        }
        result += unique
    }
    return result
}


Also note the result += unique instead of if ....


Using map, the following code has the time complexity (asymptotic notation): O(n)


package main

import "fmt"

func main() {
    r := distincts("a", "b", "c", "a")
    fmt.Println(r) // 2

}

// O(n)
func distincts(slice ...string) int {
    result := 0
    m := map[string]int{}
    for _, str := range slice {
        m[str]++
    }
    for _, v := range m {
        if v == 1 {
            result++
        }
    }
    return result
}