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