[Leetcode] 0647. Palindromic Substrings

Explore diverse LeetCode solutions in Python, C++, JavaScript, SQL, and TypeScript. Ideal for interview prep, learning, and code practice in multiple programming languages. Github Repo Link

Given a string s, return the number of palindromic substrings in it.

A string is a palindrome when it reads the same backward as forward.

substring is a contiguous sequence of characters within the string.

 

Example 1:

Input: s = "abc"
Output: 3
Explanation: Three palindromic strings: "a", "b", "c".

Example 2:

Input: s = "aaa"
Output: 6
Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".

 

Constraints:

  • 1 <= s.length <= 1000
  • s consists of lowercase English letters.

Table of contents

Python

				
					from typing import List class Solution: def maxArea(self, height: List[int]) -> int: maxSum = 0 left, right = 0, len(height) - 1 while left < right: maxSum = max(maxSum, ( right - left) * min(height[left], height[right])) if height[left] < height[right]: left += 1 else: right -= 1 return maxSum Height = [1, 8, 6, 2, 5, 4, 8, 3, 7] print(Solution().maxArea(Height))
				
			
en_USEnglish