Skip to content
Exercise · Strings and Arrays · lesson 5 of 6

Exercise: palindrome

Write a function bool is_palindrome(std::string_view s). It returns true if s is a palindrome, a string that reads the same in both directions, and false otherwise.

  • is_palindrome("abba") → true
  • is_palindrome("level") → true
  • is_palindrome("abca") → false

Constraints: letter case matters, so "Abba" is not a palindrome; an empty string and a one-character string are palindromes.

palindrome.cpp — cpp
cpp · 6 lines
Ctrl+Enter run · Esc leave editor