# 题目链接
# 题目描述
在一个字符串中找到第一个只出现一次的字符,并返回它的位置。字符串只包含 ASCII 码字符。
Input: abacc
Output: b
1
2
2
# 解题思路
先遍历一遍字符串,将其出现次数存储在数组中,在按字符串遍历一次,同时按字母查询数组,如果次数为1则返回
func firstUniqChar(s string) byte {
var list [26]int
length := len(s)
for i:=0;i<length;i++ {
list[s[i]-'a']++
}
for i:=0;i<length;i++{
if list[s[i]-'a'] == 1 {
return s[i]
}
}
return ' '
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13