{"id":521,"date":"2023-09-16T15:39:10","date_gmt":"2023-09-16T07:39:10","guid":{"rendered":""},"modified":"2023-09-17T00:42:13","modified_gmt":"2023-09-16T16:42:13","slug":"%e3%80%90leetcode%e3%80%91%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e5%8c%b9%e9%85%8d","status":"publish","type":"post","link":"https:\/\/mushiming.com\/521.html","title":{"rendered":"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d"},"content":{"rendered":"

https:\/\/www.imooc.com\/article\/281353?block_id=tuijian_wz<\/h1>\n

\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/h1>\n

2019.03.04 19:53 598\u6d4f\u89c8<\/p>\n

\u9898\u76ee\u63cf\u8ff0<\/h2>\n

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 (s) \u548c\u4e00\u4e2a\u5b57\u7b26\u6a21\u5f0f (p)\u3002\u5b9e\u73b0\u652f\u6301 \u2018.\u2019 \u548c \u2018*\u2019 \u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u3002<\/p>\n

\u2018.\u2019 \u5339\u914d\u4efb\u610f\u5355\u4e2a\u5b57\u7b26\u3002
\u2018*\u2019 \u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u524d\u9762\u7684\u5143\u7d20\u3002
\u5339\u914d\u5e94\u8be5\u8986\u76d6\u6574\u4e2a\u5b57\u7b26\u4e32 (s) \uff0c\u800c\u4e0d\u662f\u90e8\u5206\u5b57\u7b26\u4e32\u3002<\/p>\n

\u8bf4\u660e:<\/p>\n

s \u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e14\u53ea\u5305\u542b\u4ece a-z \u7684\u5c0f\u5199\u5b57\u6bcd\u3002
p \u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e14\u53ea\u5305\u542b\u4ece a-z \u7684\u5c0f\u5199\u5b57\u6bcd\uff0c\u4ee5\u53ca\u5b57\u7b26 . \u548c *\u3002
\u793a\u4f8b 1:<\/p>\n

 <\/p>\n\n\n\n
\n
1\n2\n3\n4\n5<\/pre>\n<\/td>\n
\n
\u8f93\u5165:\ns = \"aa\"\np = \"a\"\n\u8f93\u51fa: false\n\u89e3\u91ca: \"a\" \u65e0\u6cd5\u5339\u914d \"aa\" \u6574\u4e2a\u5b57\u7b26\u4e32\u3002<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

\u793a\u4f8b 2:<\/p>\n

 <\/p>\n\n\n\n
\n
1\n2\n3\n4\n5<\/pre>\n<\/td>\n
\n
\u8f93\u5165:\ns = \"aa\"\np = \"a*\"\n\u8f93\u51fa: true\n\u89e3\u91ca: '*' \u4ee3\u8868\u53ef\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u524d\u9762\u7684\u5143\u7d20, \u5373\u53ef\u4ee5\u5339\u914d 'a' \u3002\u56e0\u6b64, \u91cd\u590d 'a' \u4e00\u6b21, \u5b57\u7b26\u4e32\u53ef\u53d8\u4e3a \"aa\"\u3002<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

 <\/p>\n

\u793a\u4f8b 3:<\/p>\n

 <\/p>\n\n\n\n
\n
1\n2\n3\n4\n5<\/pre>\n<\/td>\n
\n
\u8f93\u5165:\ns = \"ab\"\np = \".*\"\n\u8f93\u51fa: true\n\u89e3\u91ca: \".*\" \u8868\u793a\u53ef\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a('*')\u4efb\u610f\u5b57\u7b26('.')\u3002<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

 <\/p>\n

\u793a\u4f8b 4:<\/p>\n

 <\/p>\n\n\n\n
\n
1\n2\n3\n4\n5<\/pre>\n<\/td>\n
\n
\u8f93\u5165:\ns = \"aab\"\np = \"c*a*b\"\n\u8f93\u51fa: true\n\u89e3\u91ca: 'c' \u53ef\u4ee5\u4e0d\u88ab\u91cd\u590d, 'a' \u53ef\u4ee5\u88ab\u91cd\u590d\u4e00\u6b21\u3002\u56e0\u6b64\u53ef\u4ee5\u5339\u914d\u5b57\u7b26\u4e32 \"aab\"\u3002<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

 <\/p>\n

\u793a\u4f8b 5:<\/p>\n

 <\/p>\n\n\n\n
\n
1\n2\n3\n4<\/pre>\n<\/td>\n
\n
\u8f93\u5165:\ns = \"mississippi\"\np = \"mis*is*p*.\"\n\u8f93\u51fa: false<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

 <\/p>\n

\u9898\u76ee\u96be\u5ea6\uff1a<\/p>\n

\u9898\u76ee\u89e3\u6790<\/h2>\n

\u8fd9\u662f\u4e00\u9053\u6709\u70b9\u96be\u5ea6\u7684\u9898\uff0c\u5982\u679c\u4f60\u770b\u4e86\u4e00\u904d\u9898\u76ee\u4e4b\u540e\uff0c\u6ca1\u6709\u4ec0\u4e48\u597d\u7684\u60f3\u6cd5\uff0c\u4e0d\u7528\u5fc3\u6025\uff0c\u6df1\u547c\u5438\uff0c\u8ba9\u6211\u4eec\u4e00\u8d77\u6765\u63a2\u7d22\u5982\u4f55\u89e3\u51b3\u8fd9\u9053\u9898\u3002<\/p>\n

\u5176\u5b9e\u9898\u76ee\u7684\u8981\u6c42\uff0c\u5c31\u662f\u5b9e\u73b0\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5373.<\/code>\u4e0e*<\/code>\u7684\u5339\u914d\uff0c\u4e00\u63d0\u5230\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4f60\u4e5f\u8bb8\u4f1a\u60f3\u5230\u5f62\u5982 ^[A-Z]:\\\\{1,2}[^\/:\\*\\?<>\\|]+\\.(jpg|gif|png|bmp)$<\/code> \u4e4b\u7c7b\u7684\u4e00\u5927\u4e32\u4e71\u4e03\u516b\u7cdf\u7684\u4ee3\u7801\uff0c\u89c9\u5f97\u770b\u7740\u90fd\u86cb\u75bc\uff0c\u8fd8\u8981\u8ba9\u6211\u6765\u5b9e\u73b0\uff1f\uff1f\uff1femmmm\uff0c\u4e0d\u8981\u65b9\uff0c\u95ee\u9898\u4e0d\u5927\uff0c\u4e0d\u8981\u88ab\u6b63\u5219\u8868\u8fbe\u5f0f<\/code>\u8fd9\u4e2a\u540d\u53f7\u7ed9\u5413\u5230\uff0c\u8981\u76f8\u4fe1\uff0c\u95ee\u9898\u603b\u6bd4\u65b9\u6cd5\u591a?\u3002\u4f55\u51b5\u8fd9\u91cc\u53ea\u9700\u8981\u89e3\u6790\u4e24\u4e2a\u7279\u6b8a\u5b57\u7b26\uff0c\u5c82\u4e0d\u662f\u5c0f\u83dc\u4e00\u789f\u3002<\/p>\n

\u660e\u4eba\u4e0d\u8bf4\u9a9a\u8bdd\uff0c\u64b8\u8d77\u8896\u5b50\u5c31\u5f00\u5e72\u3002<\/p>\n

\u5148\u91cd\u65b0\u9605\u8bfb\u4e00\u904d\u9898\u76ee\uff0c\u5bf9\u9898\u76ee\u8981\u6c42\u7684\u7406\u89e3\u548c\u628a\u63e1\u5f88\u5173\u952e\uff0c\u8fd9\u51b3\u5b9a\u4e86\u4e4b\u540e\u7684\u601d\u8003\u4f1a\u4e0d\u4f1a\u8dd1\u504f\uff0c\u540e\u9762\u7684\u51e0\u4e2a\u793a\u4f8b\u53ef\u4ee5\u7528\u6765\u9a8c\u8bc1\u81ea\u5df1\u7406\u89e3\u662f\u5426\u6b63\u786e\u3002<\/p>\n

\u4ece\u540e\u9762\u7ed9\u7684\u6817\u5b50\u91cc\u53ef\u4ee5\u770b\u51fa\uff0c\u9898\u76ee\u7684\u610f\u601d\u662f\u8981\u6c42\u5b57\u7b26\u4e32s\u4e0e\u5b57\u7b26\u6a21\u5f0fp\u80fd\u5b8c\u5168\u5339\u914d\u624d\u80fd\u7b97\u662f\u901a\u8fc7\uff0c\u800c\u4e0d\u662f\u5728s\u4e2d\u627e\u5230\u4e00\u4e2ap\u80fd\u5339\u914d\u7684\u5b50\u5b57\u7b26\u4e32\u3002<\/p>\n

\u8111\u888b\u4e00\u62cd\uff0c\u90a3\u4e00\u4e2a\u5b57\u7b26\u4e00\u4e2a\u5b57\u7b26\u6765\u5339\u914d\u4e0d\u5c31\u5b8c\u4e8b\u4e86\uff1f\u55ef\uff0c\u5148\u8bd5\u8bd5\u770b\u3002\u628a\u9898\u4e2d\u7684\u6817\u5b50\u62ff\u51fa\u6765\u753b\u6210\u56fe\uff0c\u7136\u540e\u8fdb\u884c\u89c2\u5bdf\u3002<\/p>\n

\"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

\"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

\"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

\"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

\"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

\u5728\u5f62\u6210\u81ea\u5df1\u7684\u601d\u8def\u540e\uff0c\u4e00\u5b9a\u8981\u5bf9\u8fd9\u51e0\u4e2a\u6817\u5b50\u8fdb\u884c\u9a8c\u8bc1\uff0c\u4e0d\u7136\u4ee3\u7801\u5199\u5b8c\u4ee5\u540e\u624d\u53d1\u73b0\u7406\u89e3\u9519\u4e86\u9898\u76ee\u7684\u610f\u601d\u5c31\u5f88\u5c34\u5c2c\u4e86\u3002<\/p>\n

\u5bf9\u4e8e\u4e00\u4e2a\u4f4d\u4e8e\u5b57\u7b26\u6a21\u5f0fp\u4e2d\u7684\u5b57\u7b26c\u6765\u8bf4\uff0c\u53ea\u6709\u4e09\u79cd\u60c5\u51b5\uff1a<\/p>\n

    \n
  1. \n

    c == \u2018.\u2019<\/p>\n<\/li>\n

  2. \n

    c == \u2018*\u2019<\/p>\n<\/li>\n

  3. \n

    c \u4e3a\u5176\u4ed6\u666e\u901a\u5b57\u7b26<\/p>\n<\/li>\n<\/ol>\n

    \u6211\u4eec\u5148\u6765\u770b\u7b2c\u4e00\u79cd\u60c5\u51b5\uff0c\u5f53c == '.'<\/code>\u7684\u65f6\u5019\uff0c\u56e0\u4e3a\u53ef\u4ee5\u5339\u914d\u4efb\u610f\u5b57\u7b26\uff0c\u90a3\u4e48\uff0c\u76f4\u63a5\u8df3\u8fc7\u5373\u53ef\uff0c\u5bf9\u4e8e\u7b2c\u4e09\u79cd\u60c5\u51b5\uff0c\u90a3\u4e48\u53ea\u8981s<\/code>\u4e2d\u5bf9\u5e94\u7684\u5b57\u7b26\u5b57\u7b26c<\/code>\u76f8\u540c\u5373\u53ef\uff0c\u4f60\u770b\uff0c\u5f88\u7b80\u5355\u5427\uff0c\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e09\u5206\u4e4b\u4e8c\u4e86\u3002\u63a5\u4e0b\u6765\uff0c\u518d\u6765\u770b\u770b\u6700\u540e\u4e00\u79cd\u60c5\u51b5\u3002<\/p>\n

    \u5982\u679cc == *<\/code>\uff0c\u90a3\u4e48\u4ee3\u8868\u53ef\u4ee5\u5339\u914d\u96f6\u4e2a\u6216\u8005\u591a\u4e2a\u524d\u9762\u7684\u5b57\u7b26\uff0c\u6bd4\u5982a*<\/code>\u53ef\u4ee5\u5339\u914da<\/code>\u3001aaaa<\/code>\u3001aaaaa<\/code>\u4e5f\u53ef\u4ee5\u5339\u914d\u7a7a\u5b57\u7b26\uff0c\u6240\u4ee5\u5b83\u5176\u5b9e\u662f\u4e2a\u4fee\u9970\u7b26\uff0c\u7528\u6765\u4fee\u9970\u5b83\u524d\u9762\u7684\u5b57\u7b26\uff0c\u5fc5\u987b\u8981\u8ddf\u5176\u4ed6\u5b57\u7b26\u4e00\u8d77\u4f7f\u7528\uff0c\u6240\u4ee5\u5728\u6211\u4eec\u5728\u4e00\u4e2a\u4e2a\u904d\u5386\u6a21\u5f0f\u4e32\u4e2d\u7684\u5b57\u7b26\u7684\u65f6\u5019\uff0c\u8fd8\u9700\u770b\u770b\u540e\u9762\u8ddf\u7684\u5b57\u7b26\u662f\u4e0d\u662f*<\/code>\uff0c\u5982\u679c\u662f\u7684\u8bdd\uff0c\u90a3\u4e48\u5c31\u8981\u8fdb\u884c\u7279\u6b8a\u5904\u7406\u4e86\u3002<\/p>\n

    *<\/code>\u4ee3\u8868\u5339\u914d0\u4e2a\u6216\u591a\u4e2a\u5b83\u524d\u9762\u7684\u5b57\u7b26\uff0c\u6240\u4ee5\u6709\u4e24\u79cd\u60c5\u51b5\uff0c\u4e00\u79cd\u662f0\u4e2a\uff0c\u4e00\u79cd\u662f\u591a\u4e2a\u3002<\/p>\n

    \u68b3\u7406\u4e00\u4e0b\u601d\u8def\uff0c\u6bcf\u6b21\u4ecep\u4e2d\u62ff\u51fa\u4e00\u4e2a\u5b57\u7b26\u6765\u4e0es\u4e2d\u7684\u5b57\u7b26\u8fdb\u884c\u5339\u914d\uff0c\u5982\u679c\u8be5\u5b57\u7b26\u540e\u7eed\u7684\u5b57\u7b26\u4e0d\u662f*<\/code>\uff0c\u90a3\u4e48\u76f4\u63a5\u4e0es\u4e2d\u5bf9\u5e94\u5b57\u7b26\u8fdb\u884c\u5339\u914d\u5224\u65ad\u5373\u53ef\uff0c\u5982\u679c\u5339\u914d\u4e0a\u4e86\uff0c\u90a3\u4e48\u5c31\u5c06\u4e24\u4e2a\u6e38\u6807\u90fd\u5f80\u540e\u79fb\u52a8\u4e00\u4f4d\u3002\u5982\u679c\u5339\u914d\u8fc7\u7a0b\u4e2d\u9047\u5230\u4e0d\u76f8\u7b49\u7684\u60c5\u51b5\uff0c\u5219\u76f4\u63a5\u8fd4\u56defalse\u3002\u5982\u679c\u540e\u7eed\u5b57\u7b26\u662f*<\/code>\uff0c\u90a3\u4e48\u5c31\u5982\u4e0a\u9762\u6240\u5206\u6790\u7684\uff0c\u5206\u6210\u4e24\u79cd\u60c5\u51b5\uff0c\u4e00\u79cd\u662f\u5339\u914d0\u4e2a\uff0c\u90a3\u4e48\u53ea\u9700\u8981\u8df3\u8fc7p\u4e2d\u7684\u8fd9\u4e24\u4e2a\u5b57\u7b26\uff0c\u7ee7\u7eed\u4e0es\u4e2d\u7684\u5b57\u7b26\u8fdb\u884c\u6bd4\u8f83\u5373\u53ef\uff0c\u5982\u679c\u662f\u5339\u914d\u591a\u4e2a\uff0c\u90a3\u4e48\u5c06s\u4e2d\u7684\u6e38\u6807\u5f80\u540e\u79fb\u52a8\u4e00\u4e2a\uff0c\u7ee7\u7eed\u8fdb\u884c\u5224\u65ad\uff0c\u8fd9\u4e24\u4e2a\u6761\u4ef6\u53ea\u8981\u5176\u4e2d\u4e00\u4e2a\u80fd\u6ee1\u8db3\u5373\u53ef\u3002<\/p>\n

    \u5bf9\u4e8e\u4e0a\u9762\u5206\u6790*<\/code>\u5b57\u7b26\u7684\u8bf4\u660e\u4e5f\u8bb8\u8fd8\u4e0d\u591f\u6e05\u6670\uff0c\u7ee7\u7eed\u753b\u56fe\uff1a<\/p>\n

    \"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

    \"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

    \"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

    \"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

    \u7b49\u7b49\uff0c\u4f60\u6709\u6ca1\u6709\u95fb\u5230\u4e00\u4e1d\u9012\u5f52\u7684\u5473\u9053\uff0c\u65e2\u7136\u5bf9\u4e8e\u6bcf\u4e2a\u5728\u6a21\u5f0f\u4e32\u4e2d\u7684\u5b57\u7b26\u90fd\u53ef\u4ee5\u91c7\u7528\u76f8\u540c\u7684\u7b56\u7565\u8fdb\u884c\u5904\u7406\uff0c\u90a3\u4e0d\u5c31\u662f\u6697\u793a\u8fd9\u91cc\u53ef\u4ee5\u4f7f\u7528\u9012\u5f52\u5417\u3002\u673a\u667a\u5982\u6211<\/p>\n

    \u9012\u5f52\u89e3\u6cd5<\/h2>\n

    \u5148\u6765\u5199\u4e00\u4e0b\u4f2a\u4ee3\u7801\u6765\u7ee7\u7eed\u7406\u6e05\u601d\u8def\uff0c\u6bd5\u7adf\u8fd9\u53ef\u662f\u4e00\u9053\u590d\u6742\u5ea6\u4e3a\u4e09\u661f\u7ea7\u522b\u7684\u9898\uff0c\u4e07\u4e07\u4e0d\u53ef\u8f7b\u654c\u3002<\/p>\n

     <\/p>\n\n\n\n
    \n
    1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14<\/pre>\n<\/td>\n
    \n
    boolean isMatch (String s, String p){\n    \u4ecep\u4e2d\u53d6\u51fa\u5b57\u7b26c1\uff0c\u4eces\u4e2d\u53d6\u51fa\u5b57\u7b26d1\n    \u4ecep\u4e2d\u518d\u53d6\u4e00\u4e2a\u5b57\u7b26c2\n    if (c2 == '*'){\n        \u8df3\u8fc7c1\u4e0ec2\u6216\u8005\u5c06s\u7684\u6e38\u6807\u5f80\u540e\u79fb\u52a8\u4e00\u4f4d\n        return isMatch(s,p.subString(2)) || (( c1 == '.' || c1 == d1) && isMatch(s.subString(1),p)));\n    } else if(c1 == '.'){\n        \u76f4\u63a5\u8df3\u8fc7\n        return isMatch(s.subString(1),p.subString(1);\n    } else {\n        \u666e\u901a\u5b57\u7b26\u76f4\u63a5\u6bd4\u8f83\n        return c1 == d1 && isMatch(s.subString(1), p.subString(1));\n    }\n}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

     <\/p>\n

    emmm\uff0c\u8fd9\u4e2a\u4f2a\u4ee3\u7801\u597d\u50cf\u4e0d\u592a\u5408\u683c\uff0c\u51e0\u4e4e\u628a\u4ee3\u7801\u5199\u5b8c\u4e86\uff0c23333\uff0c\u63a5\u4e0b\u6765\u53ea\u9700\u8981\u8003\u8651\u4e00\u4e0b\u8fb9\u754c\u60c5\u51b5\uff0c\u628a\u4ee3\u7801\u8865\u5168\u5c31\u884c\u4e86\uff0c\u5f53\u7136\uff0c\u8fd8\u53ef\u4ee5\u5c06\u4ee3\u7801\u7f8e\u5316\u4e00\u4e0b\uff1a<\/p>\n

     <\/p>\n\n\n\n
    \n
    1\n2\n3\n4\n5\n6\n7\n8\n9<\/pre>\n<\/td>\n
    \n
    public boolean isMatch(String s, String p){\n    if (p.length() <= 0) return s.length() <= 0;\n    boolean match = (s.length() > 0 && (s.charAt(0) == p.charAt(0) || p.charAt(0) == '.'));\n    if (p.length() > 1 && p.charAt(1) == '*'){\n        return isMatch(s, p.substring(2)) || (match && isMatch(s.substring(1), p));\n    } else {\n        return match && isMatch(s.substring(1), p.substring(1));\n    }\n}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

     <\/p>\n

    \u5927\u529f\u544a\u6210\uff0c\u63d0\u4ea4\u4e00\u4e0b\u3002<\/p>\n

    \"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

    emmm\uff0c\u9012\u5f52\u7684\u6548\u7387\u4e00\u822c\u90fd\u6bd4\u8f83\u5dee\uff0c\u53ea\u51fb\u8d25\u4e8628%\u7684\u7528\u6237\u3002<\/p>\n

    \u5f53\u7136\uff0c\u4e00\u822c\u80fd\u7528\u9012\u5f52\u89e3\u51b3\u7684\u5730\u65b9\uff0c\u90fd\u53ef\u4ee5\u4f7f\u7528\u975e\u9012\u5f52\u7684\u65b9\u5f0f\u89e3\u51b3\uff0c\u4e0b\u9762\uff0c\u6211\u4eec\u6765\u4f7f\u7528\u53e6\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n

    \u52a8\u6001\u89c4\u5212\u89e3\u6cd5<\/h2>\n

    \u52a8\u6001\u89c4\u5212\u7b80\u4ecb<\/h3>\n

    \u52a8\u6001\u89c4\u5212\uff1f\uff1f\uff1femmm\uff0c\u5982\u679c\u4f60\u4e0d\u7ecf\u5e38\u63a5\u89e6\u7b97\u6cd5\u7684\u8bdd\uff0c\u4e5f\u8bb8\u5bf9\u8fd9\u4e2a\u540d\u8bcd\u4e0d\u592a\u719f\u6089\uff0c\u6240\u4ee5\u6211\u5148\u7b80\u5355\u7684\u4ecb\u7ecd\u4e00\u4e0b\u3002<\/p>\n

    \u52a8\u6001\u89c4\u5212\uff0c\u7b80\u5355\u6765\u8bf4\u5c31\u662f\uff0c\u52a8\u6001\u7684\u53bb\u8fdb\u884c\uff0c\u89c4\u5212\u3002\u8a00\u5f52\u6b63\u4f20\uff0c\u5176\u5b9e\u52a8\u6001\u89c4\u5212\u4e5f\u662f\u4e00\u79cd\u5206\u6cbb\u7684\u601d\u60f3\uff0c\u5c06\u95ee\u9898\u5206\u89e3\u6210\u4e00\u4e2a\u4e2a\u5b50\u95ee\u9898\uff0c\u901a\u8fc7\u89e3\u51b3\u6240\u6709\u5b50\u95ee\u9898\uff0c\u6765\u6c42\u5f97\u539f\u95ee\u9898\u7684\u89e3\uff0c\u4e00\u822c\u7528\u4e8e\u6c42\u89e3\u6700\u4f18\u95ee\u9898\u3002\u4f46\u662f\u8ddf\u5206\u6cbb\u6cd5\u4e0d\u540c\u7684\u5730\u65b9\u5728\u4e8e\uff0c\u52a8\u6001\u89c4\u5212\u7684\u5b50\u95ee\u9898\u5f80\u5f80\u662f\u76f8\u4e92\u5173\u8054\u7684\uff0c\u62ff\u6700\u7b80\u5355\u7684\u6590\u6ce2\u62c9\u5951\u6570\u5217\u6765\u8bf4\uff0c\u6211\u4eec\u4f7f\u7528\u5206\u6cbb\u7684\u601d\u60f3\uff0c\u5bf9\u4e8e\u6c42fib(6)<\/code>\uff0c\u4f7f\u7528\u7684\u516c\u5f0f\u662ffib(6) = fib(5) + fib(4)<\/code>\uff0c\u4e8e\u662f\u5c06\u539f\u6765\u7684\u95ee\u9898\u4fbf\u8f6c\u5316\u4e3a\u6c42\u89e3fib(5)<\/code>\u548cfib(4)<\/code>\uff0c\u7ee7\u7eed\u9012\u5f52\uff0cfib(5) = fib(4) + fib(3)<\/code>\uff0c\u7136\u540e\u518d\u7ee7\u7eed\u9012\u5f52fib(4) = fib(3) + fib(2)<\/code>\u3001fib(3) = fib(2) + fib(1)<\/code>\u8fd9\u91ccfib(1) = 1<\/code> \u548c fib(2) = 1<\/code>\u4e3a\u521d\u59cb\u6761\u4ef6\uff0c\u4e8e\u662f\u5c31\u80fd\u6c42\u51fafib(6)<\/code>\uff0c\u521d\u770b\u8d77\u6765\u4f3c\u4e4e\u6ca1\u4ec0\u4e48\u6bdb\u75c5\uff0c\u4f46\u662f\u4ed4\u7ec6\u60f3\u4e00\u60f3\uff0c\u7531\u4e8e\u6bcf\u6b21\u9012\u5f52\u90fd\u662f\u65e0\u72b6\u6001\u7684\uff0c\u6240\u4ee5\u5176\u5b9e\u505a\u4e86\u5f88\u591a\u91cd\u590d\u7684\u8ba1\u7b97\uff0c\u753b\u4e2a\u56fe\u6765\u611f\u53d7\u4e00\u4e0b\uff1a<\/p>\n

    \u8fd9\u91cc\u5c06fib(4)\u91cd\u590d\u7b97\u4e862\u6b21\uff0cfib(3)\u7b97\u4e863\u6b21\uff0c\u8fd9\u8fd8\u53ea\u662f\u7b97fib(6)\uff0c\u5982\u679c\u662ffib(66)\u5462\uff1f\u90a3\u5c06\u4f1a\u6709\u5927\u91cf\u7684\u91cd\u590d\u8ba1\u7b97\uff0c\u8fd9\u662f\u975e\u5e38\u6d6a\u8d39\u65f6\u95f4\u7684\u3002<\/p>\n

    \u52a8\u6001\u89c4\u5212\u5c31\u53ef\u4ee5\u5f88\u597d\u7684\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u52a8\u6001\u89c4\u5212\u7684\u601d\u60f3\u8ddf\u4e0a\u9762\u662f\u4e00\u6837\u7684\uff0c\u4f46\u4e0d\u540c\u7684\u662f\uff0c\u52a8\u6001\u89c4\u5212\u4f1a\u5c06\u6bcf\u6b21\u8ba1\u7b97\u7684\u7ed3\u679c\u5b58\u8d77\u6765\uff0c\u56e0\u6b64\u5c31\u89e3\u51b3\u4e86\u3002\u7b80\u5355\u4e00\u70b9\u7406\u89e3\uff0c\u5c31\u662f\u5728\u5206\u6cbb\u7684\u57fa\u7840\u4e0a\u52a0\u5165\u4e86\u4e00\u4e2a\u72b6\u6001\u6570\u7ec4\uff0c\u6765\u5b58\u50a8\u4e2d\u95f4\u8ba1\u7b97\u7684\u7ed3\u679c\uff0c\u4ee5\u51cf\u5c11\u91cd\u590d\u8ba1\u7b97\u7684\u8017\u65f6\u3002\u5f53\u7136\uff0c\u52a8\u6001\u89c4\u5212\u53c8\u5206\u4e3a\u4e24\u79cd\uff0c\u4e00\u79cd\u662f\u81ea\u9876\u5411\u4e0b\uff0c\u5c31\u662f\u521a\u624d\u6240\u8bf4\u7684\u65b9\u6cd5\uff0c\u53e6\u4e00\u4e2a\u79cd\u662f\u81ea\u5e95\u5411\u4e0a\uff0c\u8fd8\u662f\u62ff\u4e0a\u9762\u7684\u6590\u6ce2\u62c9\u5951\u6570\u5217\u6765\u8bf4\uff0c\u8981\u8ba1\u7b97fib(6)\uff0c\u56e0\u6b64\u6211\u4eec\u5148\u8ba1\u7b97fib(3) = fib(2) + fib(1)<\/code>\uff0c\u518d\u8ba1\u7b97fib(4) = fib(3) + fib(2)<\/code>\u548cfib(5) = fib(4) + fib(3)<\/code>\uff0c\u8fd9\u6837\uff0c\u5c31\u80fd\u7b97\u51fafib(6) = fib(5) + fib(4)<\/code>\u7684\u7ed3\u679c\u4e86\u3002<\/p>\n

    \u5728\u52a8\u6001\u89c4\u5212\u4e2d\u6709\u51e0\u4e2a\u6bd4\u8f83\u5173\u952e\u7684\u6982\u5ff5\uff1a\u5b50\u95ee\u9898\uff0c\u72b6\u6001\uff0c\u72b6\u6001\u7a7a\u95f4\uff0c\u521d\u59cb\u72b6\u6001\uff0c\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u3002<\/p>\n

    \u5b50\u95ee\u9898\uff1a\u4e0e\u539f\u95ee\u9898\u5f62\u5f0f\u76f8\u540c\u6216\u8005\u7c7b\u4f3c\uff0c\u53ea\u4e0d\u8fc7\u89c4\u6a21\u53d8\u5c0f\u4e86\uff0c\u5b50\u95ee\u9898\u90fd\u89e3\u51b3\u540e\uff0c\u539f\u95ee\u9898\u5373\u89e3\u51b3\u3002<\/p>\n

    \u72b6\u6001\uff1a\u4e0e\u5b50\u95ee\u9898\u76f8\u5173\u7684\u5404\u4e2a\u53d8\u91cf\u7684\u4e00\u7ec4\u53d6\u503c\u5373\u4e3a\u72b6\u6001\uff0c\u72b6\u6001\u4e0e\u5b50\u95ee\u9898\u662f\u4e00\u5bf9\u4e00\u6216\u4e00\u5bf9\u591a\u7684\u5173\u7cfb\uff0c\u4ee3\u8868\u7740\u5b50\u95ee\u9898\u7684\u89e3\u3002\u4e0a\u9762\u7684\u6817\u5b50\uff0c\u72b6\u6001\u5c31\u662ffib(n)<\/code>\u7684\u503c\u3002<\/p>\n

    \u72b6\u6001\u7a7a\u95f4\uff1a\u7531\u6240\u6709\u72b6\u6001\u6784\u6210\u7684\u96c6\u5408\uff0c\u4e0a\u9762\u7684\u6817\u5b50\u6bd4\u8f83\u7b80\u5355\uff0c\u72b6\u6001\u7a7a\u95f4\u662f\u4e00\u7ef4\u7a7a\u95f4\u3002<\/p>\n

    \u72b6\u6001\u521d\u59cb\u6761\u4ef6\uff1a\u5373\u72b6\u6001\u7684\u521d\u59cb\u72b6\u6001\uff0c\u4e0a\u9762\u7684\u6817\u5b50\u91ccfib(1) = 1<\/code>\u548cfib(2) = 1<\/code>\u5c31\u662f\u521d\u59cb\u6761\u4ef6\u3002<\/p>\n

    \u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\uff1a\u7528\u6765\u8868\u793a\u72b6\u6001\u4e4b\u95f4\u662f\u5982\u4f55\u8f6c\u6362\u7684\u65b9\u7a0b\uff0c\u5373\u5982\u4f55\u4ece\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u5df2\u77e5\u7684\u72b6\u6001\u6c42\u51fa\u53e6\u4e00\u4e2a\u72b6\u6001\uff0c\u53ef\u4ee5\u4f7f\u7528\u9012\u63a8\u516c\u5f0f\u8868\u793a\u3002\u4e0a\u9762\u6817\u5b50\u7684\u516c\u5f0f\u4e3afib(n) = f(n - 1) + f(n -2) (n > 2)<\/code><\/p>\n

    \u7b97\u6cd5\u8fc7\u7a0b<\/h3>\n

    \u5173\u4e8e\u52a8\u6001\u89c4\u5212\u7684\u4ecb\u7ecd\u5c31\u7ed3\u675f\u4e86\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u770b\u5982\u4f55\u5728\u8fd9\u9053\u9898\u4e0a\u9762\u4f7f\u7528\u3002<\/p>\n

    \u6211\u4eec\u5148\u6765\u8003\u8651\u81ea\u9876\u5411\u4e0b\u7684\u7b97\u6cd5\u3002\u4e3a\u65b9\u4fbf\u8d77\u89c1\uff0c\u5047\u5b9a\u4f7f\u7528\u7b26\u53f7s[i:]<\/code>\u8868\u793a\u5b57\u7b26\u4e32s\u4e2d\u4ece\u7b2ci\u4e2a\u5b57\u7b26\u5230\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u7ec4\u6210\u7684\u5b50\u4e32\uff0cp[j:]\u5219\u8868\u793a\u6a21\u5f0f\u4e32p\u4e2d\uff0c\u4ece\u7b2cj\u4e2a\u5b57\u7b26\u5230\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u7ec4\u6210\u7684\u5b50\u4e32\uff0c\u4f7f\u7528 match(i,j)<\/code> \u8868\u793as[i:]<\/code>\u4e0ep[j:]<\/code>\u7684\u5339\u914d\u60c5\u51b5\uff0c\u5982\u679c\u80fd\u5339\u914d\uff0c\u5219\u7f6e\u4e3atrue\uff0c\u5426\u5219\u7f6e\u4e3afalse\u3002\u8fd9\u5c31\u662f\u5404\u4e2a\u5b50\u95ee\u9898\u7684\u72b6\u6001\u3002<\/p>\n

    \u90a3\u4e48\u5bf9\u4e8ematch(i,j)<\/code>\u7684\u503c\uff0c\u53d6\u51b3\u4e8ep[j + 1]<\/code>\u662f\u5426\u4e3a\u2019*\u2019\u3002<\/p>\n

    curMatch = i < s.length() && s[i] == p[j] || p[j] == \u2018.\u2019;<\/p>\n

      \n
    1. \n

      p[j + 1] != \u2018*\u2019\uff0cmatch(i,j) = curMatch && match(i + 1, j + 1)<\/p>\n<\/li>\n

    2. \n

      p[j + 1] == \u2018*\u2019\uff0cmatch(i,j) = match(i, j + 2) || curMatch && match(i + 1, j)<\/p>\n<\/li>\n<\/ol>\n

      \u8fd9\u6837\u8868\u8ff0\u4e00\u4e0b\u662f\u4e0d\u662f\u5c31\u6e05\u6670\u4e86\u4e0d\u5c11\u3002<\/p>\n

      \u4ee5s = \"aab\"; p = \"c*a*b\"<\/code>\u4e3a\u4f8b\uff0c\u5148\u6784\u5efa\u4e00\u4e2a\u4e8c\u7ef4\u72b6\u6001\u7a7a\u95f4\u6765\u5b58\u50a8\u4e2d\u95f4\u8ba1\u7b97\u5f97\u51fa\u7684\u72b6\u6001\u503c\u3002\u6a2a\u5411\u7684\u503c\u4ee3\u8868i\uff0c\u7eb5\u5411\u7684\u503c\u4ee3\u8868j\uff0cmatch(0,0)\u7684\u503c\u5373\u95ee\u9898\u7684\u89e3\uff0c\u7528f<\/code>\u4ee3\u8868false<\/code>\uff0ct<\/code>\u4ee3\u8868true<\/code>\u3002<\/p>\n

      \"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

      \u63a5\u4e0b\u6765\u63cf\u8ff0\u4e00\u4e0b\u540e\u7eed\u7684\u8ba1\u7b97\u8fc7\u7a0b\uff1a<\/p>\n

        \n
      1. \n

        \u6c42match(0,0): i = 0; j = 0; curMatch = false;<\/p>\n<\/li>\n

      2. \n

        p[1] == * -> match(0,0) = match(0,2) || false && match(1,0)<\/p>\n<\/li>\n

      3. \n

        \u8f6c\u5316\u4e3a\u6c42\u5b50\u95ee\u9898match(0,2)\u548cmatch(1,0)<\/p>\n<\/li>\n

      4. \n

        \u6c42match(0,2): i = 0; j = 2; curMatch = true;<\/p>\n<\/li>\n

      5. \n

        p[1] == * -> match(0,2) = match(0,4) || true && match(1,2)<\/p>\n<\/li>\n

      6. \n

        \u6c42match(0,4): i = 0; j = 4; curMatch = false;<\/p>\n<\/li>\n

      7. \n

        j + 1 == 5 >= p.length() -> match(0,4) = curMatch = false;<\/p>\n<\/li>\n

      8. \n

        match(0,4) = false;<\/p>\n<\/li>\n

      9. \n

        \u56de\u6eaf\u5230\u7b2c\u4e94\u6b65\uff0c\u6c42match(1,2): i = 1; j = 2; curMatch = true;<\/p>\n<\/li>\n

      10. \n

        p[3] == * -> match(1,2) = match(1,4) || true && match(2,2)<\/p>\n<\/li>\n

      11. \n

        \u6c42match(1,4): i = 1; j = 4; curMatch = false;<\/p>\n<\/li>\n

      12. \n

        j + 1 == 5 >= p.length() -> match(1,4) = curMatch = false;<\/p>\n<\/li>\n

      13. \n

        match(1,4) = false;<\/p>\n<\/li>\n

      14. \n

        \u56de\u6eaf\u5230\u7b2c10\u6b65\uff0c\u6c42match(2,2): i = 2; j = 2; curMatch = false;<\/p>\n<\/li>\n

      15. \n

        p[3] == * -> match(2,2) = match(2,4) || false && match(3,2)<\/p>\n<\/li>\n

      16. \n

        \u6c42match(2,4): i = 2; j = 4; curMatch = true;<\/p>\n<\/li>\n

      17. \n

        j + 1 == 5 >= p.length() -> match(2,4) = curMatch = true;<\/p>\n<\/li>\n

      18. \n

        match(2,4) = true;<\/p>\n<\/li>\n

      19. \n

        \u56de\u6eaf\u5230\u7b2c15\u6b65\u3002<\/p>\n<\/li>\n

      20. \n

        match(2,2) = true;<\/p>\n<\/li>\n

      21. \n

        \u56de\u6eaf\u5230\u7b2c10\u6b65\u3002<\/p>\n<\/li>\n

      22. \n

        match(1,2) = true;<\/p>\n<\/li>\n

      23. \n

        \u56de\u6eaf\u5230\u7b2c5\u6b65\u3002<\/p>\n<\/li>\n

      24. \n

        match(0,2) = true;<\/p>\n<\/li>\n

      25. \n

        \u56de\u6eaf\u5230\u7b2c2\u6b65\u3002<\/p>\n<\/li>\n

      26. \n

        match(0,0) = true;<\/p>\n<\/li>\n

      27. \n

        \u95ee\u9898\u89e3\u51b3<\/p>\n<\/li>\n<\/ol>\n

        \"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

        \u4f60\u770b\uff0c\u5176\u5b9e\u5f88\u7b80\u5355\u5427\u3002<\/p>\n

        \u63a5\u4e0b\u6765\u8f6c\u5316\u6210\u4ee3\u7801\uff1a<\/p>\n

         <\/p>\n\n\n\n
        \n
        1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36<\/pre>\n<\/td>\n
        \n
        enum Result {\n    TRUE, FALSE\n}\n\nclass Solution {\n    \/\/ \u72b6\u6001\u7a7a\u95f4\n    Result[][] memo;\n\n    public boolean isMatch(String text, String pattern) {\n        memo = new Result[text.length() + 1][pattern.length() + 1];\n        return match(0, 0, text, pattern);\n    }\n\n    public boolean match(int i, int j, String text, String pattern) {\n        if (memo[i][j] != null) {\n            return memo[i][j] == Result.TRUE;\n        }\n        boolean ans;\n        if (j == pattern.length()){\n            ans = i == text.length();\n        } else{\n            boolean curMatch = (i < text.length() &&\n                                   (pattern.charAt(j) == text.charAt(i) ||\n                                    pattern.charAt(j) == '.'));\n\n            if (j + 1 < pattern.length() && pattern.charAt(j+1) == '*'){\n                ans = (match(i, j+2, text, pattern) ||\n                       curMatch && match(i+1, j, text, pattern));\n            } else {\n                ans = curMatch && match(i+1, j+1, text, pattern);\n            }\n        }\n        memo[i][j] = ans ? Result.TRUE : Result.FALSE;\n        return ans;\n    }\n}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

         <\/p>\n

        \u6765\u8dd1\u4e00\u4e0b\u7ed3\u679c\uff1a<\/p>\n

        \"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

        \u51fb\u8d25\u4e8699.95%\uff0c\u4e0d\u9519\u4e0d\u9519\u3002<\/p>\n

        \u5df2\u7ecf\u5f88\u665a\u4e86\uff0c\u4f46\u6211\u8fd8\u662f\u60f3\u628a\u53e6\u4e00\u79cd\u65b9\u6cd5\u4e5f\u4e00\u8d77\u5199\u5b8c\u3002<\/p>\n

        \u8fd8\u6709\u4e00\u79cd\u65b9\u6cd5\uff0c\u53eb\u505a\u81ea\u5e95\u5411\u4e0a\u65b9\u6cd5\uff0c\u4e5f\u662f\u52a8\u6001\u89c4\u5212\u4e2d\u7684\u4e00\u79cd\uff0c\u8fd9\u79cd\u65b9\u6cd5\u7684\u601d\u8def\u5176\u5b9e\u5f88\u7b80\u5355\u7c97\u66b4\uff0c\u5373\u4ece\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u5f00\u59cb\u53cd\u5411\u5339\u914d\uff0c\u8fd8\u662f\u4ee5\u521a\u624d\u7684\u6817\u5b50\u4e3a\u4f8b\uff0c\u4ecei = 3, j = 5 \u5f00\u59cb\u4f9d\u6b21\u5f80\u5de6\u5f80\u4e0a\u5faa\u73af\u8ba1\u7b97\uff0cmatch(3,5) == true\uff0c\u6838\u5fc3\u7684\u903b\u8f91\u5e76\u6ca1\u6709\u53d8\u3002\u56e0\u4e3a\u6700\u8fb9\u7f18\u7684\u503c\u7684\u5339\u914d\u90fd\u662f\u53ef\u4ee5\u76f4\u63a5\u8ba1\u7b97\u51fa\u6765\u7684\uff0c\u4e0b\u9762\u63a8\u7b97\u5176\u4e2d\u7684\u4e00\u90e8\u5206\uff1a<\/p>\n

          \n
        1. \n

          match(3,5) = true;<\/p>\n<\/li>\n

        2. \n

          \u6c42match(3,4): i = 3; j = 4; curMatch = false;<\/p>\n<\/li>\n

        3. \n

          j + 1 == 5 >= p.length() -> match(3,4) = curMatch = false;<\/p>\n<\/li>\n

        4. \n

          match(3,4) = false;<\/p>\n<\/li>\n

        5. \n

          \u6c42match(3,3): i = 3; j = 3; curMatch = false;<\/p>\n<\/li>\n

        6. \n

          p[4] == b -> match(3,3) = curMatch = false;<\/p>\n<\/li>\n

        7. \n

          match(3,3) = false;<\/p>\n<\/li>\n

        8. \n

          \u6c42match(3,2): i = 3; j = 2; curMatch = false;<\/p>\n<\/li>\n

        9. \n

          p[3] == * -> match(3,2) = match(3,4) || false && match(4,2)<\/p>\n<\/li>\n

        10. \n

          match(3,2) = false;<\/p>\n<\/li>\n

        11. \n

          \u6c42match(3,1): i = 3; j = 1; curMatch = false;<\/p>\n<\/li>\n

        12. \n

          p[2] == a -> match(3,1) = curMatch = false;<\/p>\n<\/li>\n

        13. \n

          match(3,1) = false;<\/p>\n<\/li>\n

        14. \n

          \u6c42match(3,0): i = 3; j = 0; curMatch = false;<\/p>\n<\/li>\n

        15. \n

          p[1] == * -> match(3,0) = match(3,2) || false && match(4,0)<\/p>\n<\/li>\n

        16. \n

          match(3,0) = false;<\/p>\n<\/li>\n

        17. \n

          \u2026.<\/p>\n<\/li>\n<\/ol>\n

          \u5269\u4e0b\u7684\u90e8\u5206\u53ef\u4ee5\u81ea\u884c\u63a8\u5bfc\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

           <\/p>\n\n\n\n
          \n
          1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20<\/pre>\n<\/td>\n
          \n
          class Solution {\n    public boolean isMatch(String text, String pattern) {\n        boolean[][] memo = new boolean[text.length() + 1][pattern.length() + 1];\n        memo[text.length()][pattern.length()] = true;\n\n        for (int i = text.length(); i >= 0; i--){\n            for (int j = pattern.length() - 1; j >= 0; j--){\n                boolean curMatch = (i < text.length() &&\n                                       (pattern.charAt(j) == text.charAt(i) ||\n                                        pattern.charAt(j) == '.'));\n                if (j + 1 < pattern.length() && pattern.charAt(j+1) == '*'){\n                    memo[i][j] = memo[i][j+2] || curMatch && memo[i+1][j];\n                } else {\n                    memo[i][j] = curMatch && memo[i+1][j+1];\n                }\n            }\n        }\n        return memo[0][0];\n    }\n}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

           <\/p>\n

          \u63d0\u4ea4\u4e00\u4e0b\uff1a<\/p>\n

          \"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n

          \u6548\u7387\u4e5f\u662f\u76f8\u5f53\u9ad8\u7684\uff0c\u867d\u7136\u6bd4\u81ea\u9876\u5411\u4e0b\u65b9\u6cd5\u591a\u8ba1\u7b97\u4e86\u4e0d\u5c11\u503c\uff0c\u4f46\u662f\u51cf\u5c11\u4e86\u65b9\u6cd5\u8c03\u7528\u6b21\u6570\uff0c\u7701\u53bb\u4e86\u591a\u6b21\u9012\u5f52\u8c03\u7528\u65b9\u6cd5\u7684\u5f00\u9500\uff0c\u800c\u4e14\u6bcf\u6b21\u8ba1\u7b97\u7684\u8fc7\u7a0b\u76f8\u5f53\u7b80\u5355\uff0c\u6240\u4ee5\u5e76\u4e0d\u80fd\u8bf4\u5b83\u7684\u6548\u7387\u6bd4\u81ea\u9876\u5411\u4e0b\u7684\u65b9\u6cd5\u4f4e\uff0c\u8981\u89c6\u5177\u4f53\u60c5\u51b5\u800c\u5b9a\u3002<\/p>\n

          \u603b\u7ed3<\/h2>\n

          \u5199\u5230\u8fd9\uff0c\u4eca\u5929\u7684\u9898\u603b\u7b97\u662f\u5b8c\u6210\u7684\u5dee\u4e0d\u591a\u4e86\uff0c\u957f\u547c\u4e00\u53e3\uff0c\u6765\u56de\u987e\u4e00\u4e0b\u4eca\u5929\u7684\u6536\u83b7\u5427\uff1a<\/p>\n

          \u9996\u5148\u6211\u4eec\u7528\u5206\u6cbb\u6cd5\uff0c\u4f7f\u7528\u9012\u5f52\u6765\u89e3\u51b3\uff0c\u4f46\u662f\u6548\u7387\u504f\u4f4e\u3002<\/p>\n

          \u4e8e\u662f\u6211\u4eec\u7528\u4e86\u52a8\u6001\u89c4\u5212\u7684\u601d\u60f3\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4e0e\u5206\u6cbb\u6cd5\u6700\u5927\u7684\u4e0d\u540c\u4fbf\u5728\u4e8e\u52a8\u6001\u89c4\u5212\u4f1a\u5b58\u50a8\u4e2d\u95f4\u7684\u8ba1\u7b97\u72b6\u6001\uff0c\u4ee5\u51cf\u5c11\u91cd\u590d\u8ba1\u7b97\u3002<\/p>\n

          \u5148\u662f\u7528\u4e86\u81ea\u9876\u5411\u4e0b\u7684\u65b9\u6cd5\uff0c\u8ddf\u5206\u6cbb\u6cd5\u51e0\u4e4e\u6ca1\u6709\u5dee\u5f02\uff0c\u53ea\u662f\u591a\u4f7f\u7528\u4e86\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u3002<\/p>\n

          \u63a5\u7740\u7528\u81ea\u5e95\u5411\u4e0a\u7684\u65b9\u6cd5\u6765\u89e3\u51b3\uff0c\u4ece\u6700\u540e\u7684\u5b57\u7b26\u5f00\u59cb\u5339\u914d\uff0c\u5c06\u591a\u6b21\u9012\u5f52\u8c03\u7528\u8f6c\u4e3a\u5728\u4e00\u4e2a\u5faa\u73af\u4f53\u4e2d\u5b8c\u6210\u3002<\/p>\n

          \u603b\u7ed3\u4e00\u4e0b\u52a8\u6001\u89c4\u5212\u7684\u6b65\u9aa4\uff1a<\/p>\n

            \n
          1. \n

            \u62bd\u8c61\u95ee\u9898\u3002\u5c06\u95ee\u9898\u5206\u89e3\u4e3a\u591a\u4e2a\u5b50\u95ee\u9898\uff0c\u5b50\u95ee\u9898\u7684\u89e3\u4e00\u65e6\u6c42\u51fa\u5c31\u4f1a\u88ab\u4fdd\u5b58\u3002<\/p>\n<\/li>\n

          2. \n

            \u786e\u5b9a\u72b6\u6001\u3002\u786e\u8ba4\u6211\u4eec\u8981\u6c42\u89e3\u7684\u5b50\u95ee\u9898\u7684\u72b6\u6001\u7a7a\u95f4\uff0c\u5e76\u8bbe\u7f6e\u521d\u59cb\u72b6\u6001\u3002<\/p>\n<\/li>\n

          3. \n

            \u786e\u5b9a\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u3002\u8fd9\u4e00\u6b65\u662f\u6700\u96be\u4e5f\u662f\u6700\u91cd\u8981\u7684\u4e00\u6b65\u3002<\/p>\n<\/li>\n<\/ol>\n

             <\/p>\n

            JAVA\u7b97\u6cd5<\/p>\n","protected":false},"excerpt":{"rendered":"\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914dhttps:\/\/www.imooc.com\/article\/281353?block_id=tuijian_wz\u3010LeetCode\u3011\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d2019.03.0...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/521"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=521"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/521\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}