efficient python


  • 0
    F
        def countSubstrings(self, s):
            n = len(s)
    
            def extend(i, j):
                count = 0
                while i >= 0 and j < n and s[i] == s[j]:
                    count += 1
                    i -= 1
                    j += 1
                return count
    
            return sum(extend(i, i) + extend(i, i + 1) for i in range(n))

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.