#647
Palindromic Substrings
medium· 1-D DPruns: 0Given a string s, return the number of palindromic substrings in it. A string is palindromic if it reads the same forward and backward. Different start or end indices count as different substrings even if they consist of the same characters.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 456
class Solution:
def countSubstrings(self, s: str) -> int:
count = 0
def expand(left: int, right: int) -> int:
local = 0
while left >= 0 and right < len(s) and s[left] == s[right]:
local += 1
left -= 1
right += 1
return local
for i in range(len(s)):
count += expand(i, i)
count += expand(i, i + 1)
return count
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.