Last active
July 21, 2021 07:36
-
-
Save azihsoyn/9b78df862dfe735d9246039bd33196a0 to your computer and use it in GitHub Desktop.
This file contains 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() { | |
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