Golang solution (regex)

  • 0

    Using a regex to prepare the string as needed, followed by a normal string palindrome algorithm.

    func isPalindrome(s string) bool {
    	str:=strings.Join(regexp.MustCompile("([[:alpha:]]|\\d)*").FindAllString(strings.ToLower(s), -1),"")
    	for a, z := 0, len(str)-1; a < z; a, z = a+1, z-1 {
    		if str[a] != str[z] {
    			return false
    	return true

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.