-
Notifications
You must be signed in to change notification settings - Fork 0
/
dddt.go
53 lines (46 loc) · 887 Bytes
/
dddt.go
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
@Time : 2021/4/12 20:57
@Author : ZhaoJunfeng
@File : dddt
*/
package main
import "fmt"
func main() {
s := "tabcballabcdcba"
var Slist = make([]string, 0, len(s))
n := len(s)
for i := range s {
for j := i; j < n; j++ {
Slist = append(Slist, s[i:j])
}
}
var res string
max := 0
for h := range Slist {
if ok := isHWs(Slist[h]); ok {
if yes:=isXmax(len(Slist[h]),max);yes {
max = len(Slist[h])
res = Slist[h]
}
}
}
fmt.Printf("res :%s",res)
}
func isHWs(s string) bool {
n := len(s)
if n == 0 {
return false
}
for i := 0; i <= n/2; i++ {
if s[i] != s[n-i+1] {
return false
}
}
return true
}
func isXmax(x, y int) bool {
if x > y {
return true
}
return false
}