You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func firstUniqueLetter(s string) int {
var charArr [26]int
for i, v := range s {
arrIndex := v - 'a'
if charArr[arrIndex] == 0 {
// 这里的index + 1和默认的0区分开
// -1 char有重复,0 初始化,>0 唯一的index
charArr[arrIndex] = i + 1
} else {
charArr[arrIndex] = -1
}
}
index := -1
for _, v := range charArr {
// >0 的值为唯一的index,同时获取到最小的index
if v > 0 && (index == -1 || v-1 < index) {
index = v - 1
}
}
return index
}
The text was updated successfully, but these errors were encountered: