{"id":3092,"date":"2022-05-05T21:03:52","date_gmt":"2022-05-05T13:03:52","guid":{"rendered":"https:\/\/www.zeroheart.xyz\/wordpress\/?p=3092"},"modified":"2022-05-05T21:03:52","modified_gmt":"2022-05-05T13:03:52","slug":"%e7%ae%97%e6%b3%95%e5%9f%ba%e7%a1%80%e7%ac%ac17%e5%a4%a9","status":"publish","type":"post","link":"https:\/\/www.zeroheart.xyz\/wordpress\/?p=3092","title":{"rendered":"\u7b97\u6cd5\u57fa\u7840\u7b2c17\u5929"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/delete-operation-for-two-strings\/\">583. \u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5220\u9664\u64cd\u4f5c<\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><br><em>\/**<br><\/em><em> 583. \u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5220\u9664\u64cd\u4f5c<br><\/em><em> \u7ed9\u5b9a\u4e24\u4e2a\u5355\u8bcd word1 \u548c word2 \uff0c\u8fd4\u56de\u4f7f\u5f97 word1 \u548c  word2 \u76f8\u540c\u6240\u9700\u7684\u6700\u5c0f\u6b65\u6570\u3002<br><\/em><em><br><\/em><em> \u6bcf\u6b65 \u53ef\u4ee5\u5220\u9664\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u3002<br><\/em><em><br><\/em><em><br><\/em><em><br><\/em><em> \u793a\u4f8b 1\uff1a<br><\/em><em><br><\/em><em> \u8f93\u5165: word1 = \"sea\", word2 = \"eat\"<br><\/em><em> \u8f93\u51fa: 2<br><\/em><em> \u89e3\u91ca: \u7b2c\u4e00\u6b65\u5c06 \"sea\" \u53d8\u4e3a \"ea\" \uff0c\u7b2c\u4e8c\u6b65\u5c06 \"eat \"\u53d8\u4e3a \"ea\"<br><\/em><em> \u793a\u4f8b  2:<br><\/em><em><br><\/em><em> \u8f93\u5165\uff1aword1 = \"leetcode\", word2 = \"etco\"<br><\/em><em> \u8f93\u51fa\uff1a4<br><\/em><em><br><\/em><em><br><\/em><em> \u63d0\u793a\uff1a<br><\/em><em><br><\/em><em> 1 &lt;= word1.length, word2.length &lt;= 500<br><\/em><em> word1 \u548c word2 \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd<br><\/em><em><br><\/em><em> * <\/em><strong><em>@author <\/em><\/strong><em>zeroheart<br><\/em><em> *<br><\/em><em> *\/<br><\/em>public class Question583 {<br>    public int minDistance(String word1, String word2) {<br>        \/\/ dp[i][j] \u8868\u793a0-i, 0-j \u76f8\u540c\u7684\u6700\u5c0f\u8ddd\u79bb<br><br>        int length = word1.length();<br>        int length2 = word2.length();<br>        int [][] dp = new int[length+1][length2+1];<br><br>        for(int i = 0; i&lt;=length; i++){<br>            dp[i][0] = i; \/\/ \u5220\u9664\u6240\u6709\u5143\u7d20\uff0c\u4e0e\u7a7a\u4e32\u76f8\u540c<br>        }<br>        for(int j = 0; j&lt;=length2; j++){<br>            dp[0][j] = j; \/\/ \u5220\u9664\u6240\u6709\u5143\u7d20\uff0c\u4e0e\u7a7a\u4e32\u76f8\u540c<br>        }<br><br>        for(int i = 1; i&lt;=length; i++){<br>            for(int j = 1; j&lt;=length2; j++){<br>                if(word1.charAt(i-1) == word2.charAt(j-1)){<br>                    dp[i][j] = dp[i-1][j-1];<br>                }else {<br>                    dp[i][j] = Math.<em>min<\/em>(dp[i-1][j-1]+2, Math.<em>min<\/em>(dp[i-1][j]+1, dp[i][j-1]+1));<br>                }<br>            }<br>        }<br><br>        return dp[length][length2];<br>    }<br><br>    public static void main(String[] args) {<br>    }<br><br><br><br><br>}<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>583. \u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5220\u9664\u64cd\u4f5c \/** 583. \u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5220\u9664\u64cd\u4f5c \u7ed9\u5b9a\u4e24\u4e2a\u5355\u8bcd word1 \u548c word [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[155],"tags":[158],"_links":{"self":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3092"}],"collection":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3092"}],"version-history":[{"count":2,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3092\/revisions"}],"predecessor-version":[{"id":3094,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3092\/revisions\/3094"}],"wp:attachment":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}