mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-27 21:58:57 +01:00
Update data_structures/arrays/strings/palindrome.rb
This commit is contained in:
parent
7655003b6c
commit
bd6b1067c0
1 changed files with 9 additions and 2 deletions
|
@ -76,7 +76,14 @@ puts is_palindrome(s)
|
|||
#
|
||||
# Approach 2: Two Pointers
|
||||
#
|
||||
# Time Complexity: O(n)
|
||||
|
||||
#
|
||||
# Complexity Analysis:
|
||||
#
|
||||
# Time Complexity: O(n), in length n of the string. We traverse over each
|
||||
# character at most once until the two pointers meet in the middle, or when
|
||||
# we break and return early.
|
||||
# Space Complexity: O(1). No extra space required, at all.
|
||||
#
|
||||
def is_palindrome(s)
|
||||
letters_only = s.downcase.gsub(/[^0-9a-z]/i, '')
|
||||
|
|
Loading…
Reference in a new issue