Skip to content

Commit 3f8db60

Browse files
authored
Merge pull request neetcode-gh#2417 from krishna1m/0125-valid-palindrome
Create 0125-valid-palindrome.scala
2 parents 4e8e4de + d2dc41b commit 3f8db60

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

scala/0125-valid-palindrome.scala

Lines changed: 11 additions & 0 deletions
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)