Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 598 Bytes

File metadata and controls

30 lines (23 loc) · 598 Bytes

METHOD 1 (TC-0(n3) SC-0(1))

bool pal(string s,int left,int right)
    {
        while(left<right)
        {
            if(s[left++]!=s[right--])
                return false;
        }
        return true;
    }
    int countSubstrings(string s) {
        
        int ans=0;
        int n=s.size();

        for(int i=0;i<n;i++)
            for(int j=i;j<n;j++)
                if(pal(s,i,j))
                    ans++;

        return ans;
    }

Method 2(DP)