valid_palindrome

  • 2022-12-14
  • 浏览 (347)

valid_palindrome.go 源码

package string

import (
	"unicode"
)

// 验证回文串

func isPalindrome(s string) bool {
	i, j := 0, len(s)-1
	for i < j {
		if !unicode.IsLetter(rune(s[i])) && !unicode.IsDigit(rune(s[i])) {
			i++
		} else if !unicode.IsLetter(rune(s[j])) && !unicode.IsDigit(rune(s[j])) {
			j--
		} else if unicode.ToLower(rune(s[i])) != unicode.ToLower(rune(s[j])) {
			return false
		} else {
			i++
			j--
		}
	}
	return true
}

你可能感兴趣的文章

brute_force

brute_force_test

isomorphic_strings

0  赞