C++ top down approach

class Solution {
    bool dynamic(const string& A, const string& B, int m, int n, vector<vector<int>>& aux){
        if(m<=0 && n<=0)
            return true;
            return false;
            return aux[m][n];
        bool ans=false;
        if((m>0 && A[m-1]==B[n-1] )|| B[n-1]=='.'){
                ans=dynamic(A, B, m-1, n-1, aux);
        else if(B[n-1]=='*'){
            ans=dynamic(A, B, m, n-2, aux);
            if((m>0 && A[m-1]==B[n-2]) || B[n-2]=='.')
                    ans= ans || dynamic(A, B, m-1, n, aux);
        return ans;

    bool isMatch(string A, string B) {
        int m=A.size(), n=B.size();
        vector<vector<int>> aux(m+1, vector<int>(n+1, -1));
        return dynamic(A, B, m, n, aux);


This is not top down,its bottom up


It is top down.

In top down Each subsystem is then refined in yet greater detail, sometimes in many additional subsystem levels, until the entire specification is reduced to base elements. A top-down model is often specified with the assistance of “black boxes”, which makes it easier to manipulate.

In a bottom-up approach the individual base elements of the system are first specified in great detail. These elements are then linked together to form larger subsystems, which then in turn are linked, sometimes in many levels, until a complete top-level system is formed.


lol it is top down dude