Skip to content

Commit d2dc41b

Browse files
committedApr 15, 2023
Create 0125-valid-palindrome.scala
1 parent b3d1baa commit d2dc41b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
 

‎scala/0125-valid-palindrome.scala

+11
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)