Skip to content

Instantly share code, notes, and snippets.

@azihsoyn
Last active July 21, 2021 07:36
Show Gist options
  • Save azihsoyn/9b78df862dfe735d9246039bd33196a0 to your computer and use it in GitHub Desktop.
Save azihsoyn/9b78df862dfe735d9246039bd33196a0 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
fmt.Println(missingNumber([]int{3,0,1}))
}
func missingNumber(nums []int) int {
m := make(map[int]struct{}, len(nums))
for i := 0; i < len(nums)+1; i++ {
m[i] = struct{}{}
}
for _, num := range nums {
delete(m, num)
}
var ret int
for k, _ := range m {
ret = k
}
return ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment