mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-27 21:58:57 +01:00
Add solution using .reverse
This commit is contained in:
parent
c2bd60c223
commit
04a4c9aaed
1 changed files with 4 additions and 3 deletions
|
@ -20,12 +20,13 @@
|
||||||
# @return {Boolean}
|
# @return {Boolean}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Approach 1: Brute Force
|
# Approach 1: Using Ruby method .reverse
|
||||||
#
|
#
|
||||||
# Time Complexity:
|
# Time Complexity: O(n)
|
||||||
#
|
#
|
||||||
def is_palindrome(s)
|
def is_palindrome(s)
|
||||||
s.downcase
|
letters_only = s.downcase.gsub(/[^0-9a-z]/i, '')
|
||||||
|
letters_only.reverse == letters_only
|
||||||
end
|
end
|
||||||
|
|
||||||
s = 'A man, a plan, a canal: Panama'
|
s = 'A man, a plan, a canal: Panama'
|
||||||
|
|
Loading…
Reference in a new issue