Golang Solution with all testcase accepted

programming
Tags: #<Tag:0x00007f242d63cc18>

#1

/**

  • @input A : String
  • @Output string.
    */
    func getPalindrome(runes []rune, i, j int) string {
    for i >= 0 && j < len(runes) && runes[i] == runes[j] {
    i–
    j++
    }
    return string(runes[i+1 : j])
    }

func longestPalindrome(str string ) (string) {
palindrome := “”
runes := []rune(str)
for i := 0; i < len(runes); i++ {
temp := getPalindrome(runes, i, i)
if len(temp) > len(palindrome) {
palindrome = temp
//fmt.Println("Palindrome : ", palindrome)
}
temp = getPalindrome(runes, i, i+1)
if len(temp) > len(palindrome) {
palindrome = temp
//fmt.Println("Palindrome : ", palindrome)
}
}
return palindrome
}