DEV Community

vinay
vinay

Posted on

How to Delete Duplicate Numbers in Golang

#go
func Set(arr []int) []int {
    for i := 0; i < len(arr); i++ {
        for j := 0; j < len(arr); j++ {
            if arr[i] == arr[j] && i != j {
                arr = append(arr[:j],arr[j+1:]...)
            }
        }
    }
    return arr
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)