1 Star 0 Fork 0

wilson3123/go-leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
valid_palindrome.go 661 Bytes
一键复制 编辑 原始数据 按行查看 历史
zczou 提交于 9年前 . valid_palindrome
package valid_palindrome
func isPalindrome(s string) bool {
bytes := []byte(s)
i, j := 0, len(bytes)-1
L:
for i < j {
for {
if i >= j {
break L
}
if !isAlpha(bytes[i]) {
i++
} else {
break
}
}
for {
if i >= j {
break L
}
if !isAlpha(bytes[j]) {
j--
} else {
break
}
}
if toLower(bytes[i]) != toLower(bytes[j]) {
return false
}
i++
j--
}
return true
}
func toLower(b byte) byte {
if b >= 'A' && b <= 'Z' {
return 'a' + b - 'A'
}
return b
}
func isAlpha(b byte) bool {
if 'a' <= b && b <= 'z' || 'A' <= b && b <= 'Z' || '0' <= b && b <= '9' {
return true
}
return false
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wilson3123/go-leetcode.git
git@gitee.com:wilson3123/go-leetcode.git
wilson3123
go-leetcode
go-leetcode
master

搜索帮助