Menu
CoddyTech

Palindrome String

A string is a palindrome when it reads the same from left to right as from right to left, like level. Write a function that gets a string s of lowercase English letters and returns true if s is a palindrome and false otherwise.

Function

isPalindrome(s: string) → boolean
sstring
the lowercase string to check
Returnsboolean
true when s reads the same in both directions

Constraints

  • 1 ≤ s.length ≤ 5 × 104
  • s contains only lowercase English letters (a to z).

Examples

Input
s = "racecar"
Output
true
Explanation
Compare from the outside in: r with r, a with a, c with c. The middle e has no partner and needs none, so the answer is true.
challenge icon

Follow-up

How would you change the two pointers to skip spaces and punctuation and ignore case, so that Was it a car or a cat I saw counts as a palindrome?

Reset code
def isPalindrome(s):
    # Write code here

Test #1

Test #2

Test #3

Argument

s = "racecar"

Expected Output

true