https://leetcode.cn/problems/valid-palindrome/description/?envType=study-plan-v2&envId=top-interview-150

 

package leetcode150

import (
    "strings"
    "testing"
)

func TestIsPalindrome(t *testing.T) {
    s := "0P"
    res := isPalindrome(s)
    println(res)
}

func isPalindrome(s string) bool {
    s = strings.ToLower(s)
    i, j := 0, len(s)-1
    for i < j {
        if !isNumberChar(s[i]) {
            i++
            continue
        }
        if !isNumberChar(s[j]) {
            j--
            continue
        }
        if s[i] != s[j] {
            return false
        }
        i, j = i+1, j-1
    }

    return true
}

func isNumberChar(a uint8) bool {
    if (a >= '0' && a <= '9') || (a >= 'a' && a <= 'z') {
        return true
    }
    return false
}