go

package main

/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 * 
 * @param A string字符串 
 * @param n int整型 
 * @return int整型
*/
func getLongestPalindrome( A string ,  n int ) int {
    // write code here
    maxs := 0
    for i:= 0; i < n; i++ {
        m1 := findLonger(A, i, i, n)
        m2 := findLonger(A, i, i+1, n)

        maxs = max(maxs, m1, m2)
    }

    return maxs
}

func findLonger(s string, start, end int, n int) int {
    l, r := start, end
    for l >=0 && r < n {
        if s[l] != s[r] {
            break
        }
        l--
        r++
    }
    return r - l - 1
}

func max(m1, m2, m3 int) int{
    max := m1
    m := m2
    if m2 < m3 {
        m = m3
    }

    if max > m {
        return max
    }
    return m
}