valid_palindrome

2022-12-14 浏览 (774)

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

  • 所属分类: 后端技术
  • 本文标签: 技术
  • 版权声明: 本文链接 https://seaxiang.com/blog/c608170491f14a11aa0b9450ecbd4543