[C++] DP Solution with Comments Explaining the Code
Scroll right to see the full comments\n\nclass Solution {\npublic:\n    bool isMatch(string s, string p) {\n        int m = p.length() , n = s.length();\n      
Scroll right to see the full comments\n```\nclass Solution {\npublic:\n    bool isMatch(string s, string p) {\n        int m = p.length() , n = s.length();\n        vector<vector<int>> dp(m+1,vector<int>(n+1,0));\n        dp[0][0] = 1; // Empty string matches empty string\n        for(int i = 1 ; i <= m ; ++i)\n        {\n            if(p[i-1] == \'*\')\n                dp[i][0] = dp[i-1][0]; // Any number of * matches empty string // E.g : ** and \'\'\n        }\n        // Note that we are using 0-based indexing for strings and in the dp table 0th positon indicates empty string hence we are checking for p[i-1] && s[j-1]\n        for(int i = 1 ; i <= m ; ++i)\n        {\n            for(int j = 1 ; j <= n ; ++j)\n            {\n                if(p[i-1] == s[j-1] || p[i-1] == \'?\') // If the ith character of p and jth character of s is same or ith character of p is \'?\' then exclude ith and jth characters of p and s and check whether the rest of the strings upto (i-1)th in p and (j-1)th in s are matching E.g : ab and ab or ab and a?\n                    dp[i][j] = dp[i-1][j-1];\n                else // if p[i-1] != s[j-1]\n                    if(p[i-1] == \'*\')\n                    {\n                        dp[i][j] = dp[i-1][j] || dp[i][j-1]; // If ith character of p is \'*\' then we have two choices : 1) make it null character in which case we check whether string upto (i-1)th character in p and upto jth character in s are matched E.g : ab and ab* 2) match the jth character in s in which case we check whether the string upto ith character in p and (j-1) th character in s are matched E.g : abcd and ab*\n                    }\n            }\n        }\n        return dp[m][n]; // If both the strings were fully matched\n    }\n};\n```
['Dynamic Programming', 'C++']