Created
May 26, 2020 20:15
-
-
Save thiagozs/3f487f816dbd40f30a23493a0941e253 to your computer and use it in GitHub Desktop.
Challenge QuintoAndar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
A := []int{0, 3, 3, 7, 5, 3, 11, 1} | |
B := []int{0, 3, 0, 7, 0, 0, 11, 0} | |
C := []int{80, 80, 1000000000, 80, 80, 80, 80, 80, 80, 123456789} | |
fmt.Println("reduce", reduce(A)) | |
fmt.Println("reduce", reduce(B)) | |
fmt.Println("reduce", reduce(C)) | |
} | |
func reduce(arr []int) int { | |
mapper := map[uint64]uint64{} | |
for _, k := range arr { | |
if k%2 == 0 { | |
mapper[uint64(k)] = uint64(k) | |
} | |
} | |
return len(mapper) + 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment