Skip to content

Latest commit

 

History

History
21 lines (18 loc) · 402 Bytes

File metadata and controls

21 lines (18 loc) · 402 Bytes

回文串

预处理方式

package main

func handle(s string) [][]bool:
	n := len(s)
	isPalindrome := make([][]bool, n)
	for i := range isPalindrome {
		isPalindrome[i] = make([]bool, n)
		isPalindrome[i][i] = true
	}
	for i := n - 1; i >= 0; i-- {
		for j := i + 1; j < n; j++ {
			isPalindrome[i][j] = s[i] == s[j] && (i+2 >= j || isPalindrome[i+1][j-1])
		}
	}
    return isPalindrome