Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,20 +1,19 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func uniq(list []int) []int {
|
||||
unique_set := make(map[int] bool, len(list))
|
||||
for _, x := range list {
|
||||
unique_set[x] = true
|
||||
}
|
||||
result := make([]int, len(unique_set))
|
||||
i := 0
|
||||
for x := range unique_set {
|
||||
result[i] = x
|
||||
i++
|
||||
}
|
||||
return result
|
||||
unique_set := make(map[int]bool, len(list))
|
||||
for _, x := range list {
|
||||
unique_set[x] = true
|
||||
}
|
||||
result := make([]int, 0, len(unique_set))
|
||||
for x := range unique_set {
|
||||
result = append(result, x)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(uniq([]int {1,2,3,2,3,4})) // prints: [3 1 4 2]
|
||||
fmt.Println(uniq([]int{1, 2, 3, 2, 3, 4})) // prints: [3 4 1 2] (but in a semi-random order)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue