HTMLify
LeetCode - Set Mismatch - Go
Views: 317 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | func count(target int, arr []int) int { var count int for _, n := range arr { if n == target { count++ } } return count } func findErrorNums(nums []int) []int { ans := []int{0, 0} for n:=1; n<=len(nums); n++ { c := count(n, nums) if c == 0 { ans[1] = n } if c == 2 { ans[0] = n } } return ans } |