We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b3d1baa commit d2dc41bCopy full SHA for d2dc41b
scala/0125-valid-palindrome.scala
@@ -0,0 +1,11 @@
1
+object Solution {
2
+ def isPalindrome(s: String): Boolean = {
3
+ val smallCased = s.toLowerCase
4
+ // removing all non-alphanumeric characters
5
+ val notAlphaNumericRegex = """[\W_]""".r
6
+ val toCompareWith = notAlphaNumericRegex.replaceAllIn(smallCased, "")
7
+
8
+ val reversed = toCompareWith.reverse
9
+ toCompareWith == reversed
10
+ }
11
+}
0 commit comments