text: // Hi, I'm Yanzhan. I'm interested in all kinds of algorithmic problems. Also, I'm fascinated with javascript. If you want to learn more about programming problems and javascript, please visit my Youtube Channel (https://www.youtube.com/channel/UCDkz-__gl3frqLexukpG0DA?view_as=subscriber), Twitter Account (https://twitter.com/YangYanzhan), GitHub Repo (https://github.com/yangyanzhan/code-camp) or HomePage (https://yanzhan.site/).
  
  /**
   * @param {string} s
   * @param {string} p
   * @return {boolean}
   */
  
  var isMatch = function(s, p) {
      var tmp = "";
      for (var i = 0; i < p.length; i++) {
          if (p[i] == "*") {
              if (i > 0 && p[i - 1] == "*") {
                  continue;
              }
          }
          tmp += p[i];
      }
      p = tmp;
      if (p.length == 0) {
          return s.length == 0;
      } else {
          if (s.length == 0) {
              return p == "*";
          }
      }
      var nS = s.length, nP = p.length;
      var dp = [];
      for (var i = 0; i < nS; i++) {
          var row = [];
          for (var j = 0; j < nP; j++) {
              row.push(false);
          }
          dp.push(row);
      }
      dp[0][0] = p[0] == "*" || p[0] == "?" || p[0] == s[0];
      for (var i = 1; i < nS; i++) {
          dp[i][0] = p[0] == "*";
      }
      for (var j = 1; j < nP; j++) {
          if (p[j] == "*") {
              dp[0][j] = dp[0][j - 1];
          } else if (p[j] == "?" || p[j] == s[0]) {
              var valid = true;
              for (var k = j - 1; k >= 0; k--) {
                  if (p[k] != "*") {
                      valid = false;
                      break;
                  }
              }
              dp[0][j] = valid;
          }
          if (!dp[0][j]) {
              break;
          }
      }
      for (var i = 1; i < nS; i++) {
          for (var j = 1; j < nP; j++) {
              if (p[j] == "*") {
                  var valid = false;
                  for (var k = 0; k <= i; k++) {
                      if (dp[k][j - 1]) {
                          valid = true;
                          break;
                      }
                  }
                  dp[i][j] = valid;
              } else if (p[j] == "?" || p[j] == s[i]) {
                  dp[i][j] = dp[i - 1][j - 1];
              }
          }
      }
      return dp[nS - 1][nP - 1];
  };
  