← All problems

Longest Palindromic Substring

Medium stringstwo-pointersdynamic programming LeetCode ↗
Given a string s, return the longest palindromic substring it contains. A palindrome reads the same forward and backward. If several answers tie, any one is acceptable.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n^2), Space O(1)

Common pitfalls

  • Only checking odd-length centers
  • O(n^3) checking every substring

Your solution

Log in to save your code and track progress.