回文检测
# Go 语言实现回文检测
package main
import (
"strings"
)
/**
回文检测,正序和逆序读是一样的
*/
func Prime(s string) bool {
var temp = strings.Split(s, "")
for i, j := 0, len(temp) - 1; i < j; {
if temp[i] != temp[j] {
return false
}
i++
j--
}
return true
}
func main() {
print(Prime("上海自来水来自海上"))
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
编辑 (opens new window)
上次更新: 2022/07/10, 22:04:41