add new solutions
This commit is contained in:
parent
9a10695e8c
commit
ca24d0a56a
30 changed files with 697 additions and 16 deletions
22
solutions/6/q645/solution.go
Normal file
22
solutions/6/q645/solution.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package q645
|
||||
|
||||
func findErrorNums(nums []int) []int {
|
||||
var duplicated, missing int
|
||||
seen := make([]bool, len(nums))
|
||||
|
||||
for _, n := range nums {
|
||||
if seen[n-1] {
|
||||
duplicated = n
|
||||
}
|
||||
seen[n-1] = true
|
||||
}
|
||||
for i, ok := range seen {
|
||||
if !ok {
|
||||
missing = i + 1
|
||||
break
|
||||
}
|
||||
}
|
||||
return []int{duplicated, missing}
|
||||
}
|
||||
|
||||
var _ = findErrorNums
|
||||
Loading…
Add table
Add a link
Reference in a new issue