Longest Palindromic Substring
Given a string s, return the longest contiguous substring of s that reads the same forwards and backwards. If several have the maximum length, any one of them is accepted.
Open official problem prompt ↗Find the longest stretch of consecutive characters that is a mirror image of itself.
Standing at each seam of a row of tiles and pushing both hands outward as long as the tiles on the left and right match -- the widest symmetric span you reach is the answer.
- Input
- s = "babad"
- Output
- "bab"
- Why
- "bab" is a palindrome of length 3; "aba" is an equally valid alternative.
1 <= s.length <= 1000s consists of digits and English letters