tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,20 @@
|
|||
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
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(uniq([]int {1,2,3,2,3,4})) // prints: [3 1 4 2]
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func uniq(list []int) []int {
|
||||
unique_set := make(map[int]int, len(list))
|
||||
i := 0
|
||||
for _, x := range list {
|
||||
if _, there := unique_set[x]; !there {
|
||||
unique_set[x] = i
|
||||
i++
|
||||
}
|
||||
}
|
||||
result := make([]int, len(unique_set))
|
||||
for x, i := range unique_set {
|
||||
result[i] = x
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(uniq([]int{1, 2, 3, 2, 3, 4})) // prints: [1 2 3 4]
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
func uniq(list []float64) []float64 {
|
||||
unique_set := map[float64]int{}
|
||||
i := 0
|
||||
nan := false
|
||||
for _, x := range list {
|
||||
if _, exists := unique_set[x]; exists {
|
||||
continue
|
||||
}
|
||||
if math.IsNaN(x) {
|
||||
if nan {
|
||||
continue
|
||||
} else {
|
||||
nan = true
|
||||
}
|
||||
}
|
||||
unique_set[x] = i
|
||||
i++
|
||||
}
|
||||
result := make([]float64, len(unique_set))
|
||||
for x, i := range unique_set {
|
||||
result[i] = x
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(uniq([]float64{1, 2, math.NaN(), 2, math.NaN(), 4}))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue