Add solution for Challenge 17 by shansing#1437
Conversation
WalkthroughAdds a new Go solution file implementing a palindrome checker. The solution includes an exported Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
challenge-17/submissions/shansing/solution-template.go (2)
27-27: Simplify empty check:len(s) <= 0→len(s) == 0.
len()never returns a negative value, so<= 0is redundant.- if len(s) <= 0 { + if len(s) == 0 {
31-31: Compile regex once at package level to avoid repeated compilation.
regexp.MustCompileis called on every invocation ofIsPalindrome, which adds unnecessary overhead. Hoisting it to a package-level variable compiles it once at init time.Suggested fix
+var nonAlphanumericRegex = regexp.MustCompile("[^a-z0-9]+") + // IsPalindrome checks if a string is a palindrome. // A palindrome reads the same backward as forward, ignoring case, spaces, and punctuation. func IsPalindrome(s string) bool { if len(s) <= 0 { return true } // 1. Clean the string (remove spaces, punctuation, and convert to lowercase) - cleaned := regexp.MustCompile("[^a-z0-9]+").ReplaceAllString(strings.ToLower(s), "") + cleaned := nonAlphanumericRegex.ReplaceAllString(strings.ToLower(s), "") // 2. Check if the cleaned string is the same forwards and backwards
Challenge 17 Solution
Submitted by: @shansing
Challenge: Challenge 17
Description
This PR contains my solution for Challenge 17.
Changes
challenge-17/submissions/shansing/solution-template.goTesting
Thank you for reviewing my submission! 🚀