golang学习day3

楼主: SecondRun (雨夜琴声)   2024-01-25 10:45:30
125. Valid Palindrome
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
Given a string s, return true if it is a palindrome, or false otherwise.
简单说就是检查是不是回文
以下golang code
func isPalindrome(s string) bool {
slice := []int{}
for _, c := range s {
if c >= 97 && c <= 122 {
slice = append(slice, int(c))
continue
}
if c >= 65 && c <= 90 {
slice = append(slice, int(c+32))
}
if c >= 48 && c <= 57 {
slice = append(slice, int(c))
continue
}
}
i := 0
j := len(slice) - 1
for i < j {
if slice[i] == slice[j] {
i += 1
j -= 1
continue
}
return false
}
return true
}
不得不说golang在字串处理方面好像有点麻烦
资料结构也有点没那么强大的感觉
作者: sustainer123 (caster)   2023-01-25 10:45:00
大师
作者: SiranuiFlare (阿火)   2024-01-25 10:46:00
大师
作者: a000000000 (九个零喔)   2024-01-25 10:47:00
太师
作者: Firstshadow (IamCatづミ'_'ミづ)   2024-01-25 10:48:00
哪时要内推窝

Links booklink

Contact Us: admin [ a t ] ucptt.com