Sunday, December 25, 2022
String t
is generated by random shuffling string s
and then add one more letter at a random position.
A function to return the letter that was added to t
.
t
)import "strings"
func findTheDifference(s string, t string) byte {
for idx, rune := range t {
letter := string(rune)
frequencyInT := strings.Count(t, letter)
frequencyInS := strings.Count(s, letter)
if (frequencyInT > frequencyInS) {
return t[idx]
}
}
return 0
}