题目:
题解:
type pair struct {ch bytepos int
}func firstUniqChar(s string) int {n := len(s)pos := [26]int{}for i := range pos[:] {pos[i] = n}q := []pair{}for i := range s {ch := s[i] - 'a'if pos[ch] == n {pos[ch] = iq = append(q, pair{ch, i})} else {pos[ch] = n + 1for len(q) > 0 && pos[q[0].ch] == n+1 {q = q[1:]}}}if len(q) > 0 {return q[0].pos}return -1
}