golang - Counting Duplicates

Desc

Count the number of Duplicates

Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.

Example

“abcde” -> 0 # no characters repeats more than once
“aabbcde” -> 2 # ‘a’ and ‘b’
“aabBcde” -> 2 # ‘a’ occurs twice and ‘b’ twice (bandB)
“indivisibility” -> 1 # ‘i’ occurs six times
“Indivisibilities” -> 2 # ‘i’ occurs seven times and ‘s’ occurs twice
“aA11” -> 2 # ‘a’ and ‘1’
“ABBA” -> 2 # ‘A’ and ‘B’ each occur twice

Code

package main

import (
"fmt"
"strings"
"unicode/utf8"
)

func main() {
count := duplicateCount("aabbcde")
fmt.Println(count)
}

func duplicateCount(s1 string) int {
dict := make(map[rune]int, 0)
count := 0
for len(s1) > 0 {
r, size := utf8.DecodeRuneInString(strings.ToLower(s1))
// fmt.Printf("%c %v\n", r, size)
s1 = s1[size:]
if dict[r] > 1 {
continue
}
// fmt.Println(dict[r])
if dict[r] == 1 {
count++
}
dict[r]++
}
return count
}