Problem List

Valid Palindrome

May 30, 2025Go string, two pointereasy

Problem

Approach

Edge Cases

Reflections

This was a horrendous approach. I need to study up on runes, ASCII, and strings mutation.

Performance

Complexity

Go Solution
import "strings"

func isPalindrome(s string) bool {
  s = formatString(s)
  fmt.Print(s)
  left, right := 0, len(s) - 1
  for left <= right {
    leftLetter, rightLetter:= s[left], s[right]

        if leftLetter != rightLetter  {
      return false
    }

        left++
  right--
}

return true
}

func formatString(s string) string {
  s = strings.ToLower(s)
  s = strings.TrimSpace(s)

  res:= ""
  for _, letter := range s {

    if (letter >= 'a' && letter <= 'z') || (letter >= '0' && letter <= '9') {
      res += string(letter)
    }
  }

  return res
};
LeetCode Problem Link