提交 eebfd979 编写于 作者: _Fighter's avatar _Fighter

2021年12月10日

上级 5fd0977d
package main
import "fmt"
func lengthOfNonRepeatingSubStr(s string) int {
lastOccurrend := make(map[rune]int)
start := 0
maxLength := 0
// for i ,ch := range[]byte(s){ byte 修改rune 支持中文件
for i, ch := range []rune(s) {
if lastI, ok := lastOccurrend[ch]; ok && lastI >= start {
start = lastOccurrend[ch] + 1
}
if i-start+1 > maxLength {
maxLength = i - start + 1
}
lastOccurrend[ch] = i
}
for v, _ := range lastOccurrend {
fmt.Printf("(%c )", v)
}
fmt.Println()
return maxLength
}
func main() {
fmt.Println(lengthOfNonRepeatingSubStr("dafwefwefwfsdfsdf"))
fmt.Println(lengthOfNonRepeatingSubStr("我家你中国,我在家乡"))
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册