MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / isPalindrome

Function isPalindrome

valid_palindrome_125/solution.go:8–32  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

6)
7
8func isPalindrome(s string) bool {
9 front := 0
10 back := len(s) - 1
11 s = strings.ToLower(s)
12
13 for front <= back {
14 for front < len(s) && !isAlphaNumeric(string(s[front])) {
15 front++
16 }
17
18 for back > -1 && !isAlphaNumeric(string(s[back])) {
19 back--
20 }
21
22 // "a:a" case needs initial condition here
23 if front <= back && s[front] != s[back] {
24 return false
25 }
26
27 front++
28 back--
29 }
30
31 return true
32}
33
34func isAlphaNumeric(s string) bool {
35 matched, _ := regexp.MatchString("[a-z0-9]", s)

Callers 1

Test_isPalindromeFunction · 0.70

Calls 1

isAlphaNumericFunction · 0.85

Tested by 1

Test_isPalindromeFunction · 0.56