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.

lock icon+16 hidden tests on Submit

challenge icon

Follow-up

A sentence such as Was it a car or a cat I saw is a palindrome once you ignore case, spaces and punctuation. How would you change the two pointers to skip those characters?

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

Case 1

Case 2

Case 3

Input

s = "racecar"

Expected

true