func lengthOfLongestSubstring(s string) {
match := make(map[string]int)
var current string
current = s[0]
if match[current] == 1 {
///
}
}
为什么我会收到错误cannot use s[0] (type byte) as type string in assignment
?据我所知,s
的类型为string
,为什么访问一个字符会将它变成byte
?获取字符串索引
是否铸造s [0]串工作? – DJSweetness
,因为's [0]'是一个'byte',而不是'string'。你确定你只想按字节操作还是应该用utf8符文工作? – JimB
@JimB我只是想检索字符,所以我可以用它作为地图上的一个键 – chefcurry7