...

/

Solution: Check If a String Is a Palindrome

Solution: Check If a String Is a Palindrome

Go over the implementation for checking if a string is a palindrome.

Solution

Press + to interact
def is_palindrome?(string)
# i and j intialized to both ends of the string
i = 0
j = string.length - 1
while j > i
return false if string[i] != string[j]
i = i + 1
j = j - 1
end
return true
end

Explanation

  • Lines 3–4: We initialize the i and j variables to 0 and ...