Skip to content

Instantly share code, notes, and snippets.

@ericness
Created March 27, 2022 02:43
Show Gist options
  • Save ericness/865b9edf98085c986edd9132305f6e89 to your computer and use it in GitHub Desktop.
Save ericness/865b9edf98085c986edd9132305f6e89 to your computer and use it in GitHub Desktop.
LeetCode 647 Brute force solution
class Solution:
def countSubstrings(self, s: str) -> int:
"""Find number of palindromic strings in s
Args:
s (str): String to analyze
Returns:
int: Count of palindromes
"""
palindromes = 0
for i in range(len(s)):
for j in range(i, len(s)):
if s[i:j] == s[j:i:-1]:
palindromes += 1
return palindromes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment