Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Jan 22, 2024
1 parent 2709faf commit e52748e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions leetcode/645.SetMismatch/setMismatch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// https://leetcode.com/problems/set-mismatch/description/

package main

import (
"fmt"
)

func findErrorNums(nums []int) []int {
n := len(nums)
s1 := (1 + n) * n >> 1
s2, s := 0, 0
set := map[int]bool{}
for _, x := range nums {
if !set[x] {
set[x] = true
s2 += x
}
s += x
}
return []int{s - s2, s1 - s2}
}

func main() {
nums := []int{1, 2, 2, 4}

fmt.Println(findErrorNums(nums))
}

0 comments on commit e52748e

Please sign in to comment.