add new solutions
This commit is contained in:
parent
9a10695e8c
commit
ca24d0a56a
30 changed files with 697 additions and 16 deletions
25
solutions/12/q1207/solution.go
Normal file
25
solutions/12/q1207/solution.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package q1207
|
||||
|
||||
import "slices"
|
||||
|
||||
type void struct{}
|
||||
|
||||
func uniqueOccurrences(arr []int) bool {
|
||||
slices.Sort(arr)
|
||||
seen := map[int]void{}
|
||||
|
||||
for i := 0; i < len(arr); {
|
||||
c := arr[i]
|
||||
count := 0
|
||||
for ; i < len(arr) && arr[i] == c; i++ {
|
||||
count++
|
||||
}
|
||||
if _, ok := seen[count]; ok {
|
||||
return false
|
||||
}
|
||||
seen[count] = void{}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var _ = uniqueOccurrences
|
||||
Loading…
Add table
Add a link
Reference in a new issue