{"id":103875,"date":"2026-09-11T13:17:28","date_gmt":"2026-09-11T05:17:28","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/103875.html"},"modified":"2026-09-11T13:17:28","modified_gmt":"2026-09-11T05:17:28","slug":"leetcode-566%ef%bd%9c%e9%87%8d%e5%a1%91%e7%9f%a9%e9%98%b5-reshape-the-matrix","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/103875.html","title":{"rendered":"LeetCode 566\uff5c\u91cd\u5851\u77e9\u9635 Reshape the Matrix"},"content":{"rendered":"<h2>LeetCode 566&#xff5c;\u91cd\u5851\u77e9\u9635 Reshape the Matrix<\/h2>\n<p>\u8d39\u66fc\u5b66\u4e60\u6cd5\u6838\u5fc3\u601d\u8def&#xff1a;\u4e0d\u7528\u672f\u8bed&#xff0c;\u7528\u5927\u767d\u8bdd\u8bb2\u6e05\u695a&#xff0c;\u5047\u8bbe\u4f60\u8981\u8bb2\u7ed9\u4e00\u4e2a\u5c0f\u767d\u542c\u61c2&#xff1b;\u5148\u660e\u767d\u95ee\u9898\u672c\u8d28&#xff0c;\u518d\u601d\u8003\u65b9\u6848&#xff0c;\u6700\u540e\u5199\u4ee3\u7801&#xff0c;\u6bcf\u884c\u52a0\u8be6\u7ec6\u6ce8\u91ca<\/p>\n<h3>\u9898\u76ee\u4fe1\u606f<\/h3>\n<p>\u9898\u53f7&#xff1a;566<br \/>\n\u9898\u76ee\u540d\u79f0&#xff1a;\u91cd\u5851\u77e9\u9635 Reshape the Matrix<br \/>\n\u96be\u5ea6&#xff1a;\u7b80\u5355<br \/>\n\u6807\u7b7e&#xff1a;\u6570\u7ec4\u3001\u77e9\u9635\u3001\u6a21\u62df<\/p>\n<h4>\u9898\u76ee\u53d9\u8ff0<\/h4>\n<p>\u5728 MATLAB \u91cc\u9762\u6709\u4e2a reshape \u51fd\u6570&#xff0c;\u53ef\u4ee5\u628a\u4e00\u4e2a m \u00d7 n \u7684\u4e8c\u7ef4\u77e9\u9635&#xff0c;\u6539\u6210 r \u00d7 c \u7684\u65b0\u77e9\u9635&#xff0c;\u5143\u7d20\u987a\u5e8f\u4fdd\u6301\u4e0d\u53d8\u3002<\/p>\n<p>\u73b0\u5728\u7ed9\u4f60\u4e8c\u7ef4\u77e9\u9635 mat&#xff0c;\u8fd8\u6709\u4e24\u4e2a\u6b63\u6574\u6570 r&#xff08;\u76ee\u6807\u884c\u6570&#xff09;\u3001c&#xff08;\u76ee\u6807\u5217\u6570&#xff09;\u3002<br \/>\n\u89c4\u5219&#xff1a;<\/p>\n<li>\u6309\u884c\u4f18\u5148\u904d\u5386\u987a\u5e8f&#xff08;\u4ece\u4e0a\u5230\u4e0b&#xff0c;\u6bcf\u884c\u4ece\u5de6\u5411\u53f3&#xff09;\u53d6\u51fa\u6240\u6709\u5143\u7d20&#xff0c;\u4f9d\u6b21\u586b\u5145\u5230\u65b0\u77e9\u9635&#xff1b;<\/li>\n<li>\u5982\u679c\u539f\u77e9\u9635\u603b\u5143\u7d20\u6570\u91cf m*n \u4e0d\u7b49\u4e8e\u76ee\u6807\u603b\u5143\u7d20\u6570\u91cf r*c&#xff0c;\u65e0\u6cd5\u91cd\u5851&#xff0c;\u76f4\u63a5\u8fd4\u56de\u539f\u77e9\u9635&#xff1b;<\/li>\n<li>\u80fd\u91cd\u5851&#xff0c;\u8fd4\u56de\u65b0 r \u00d7 c \u77e9\u9635\u3002<\/li>\n<h5>\u793a\u4f8b1<\/h5>\n<p>\u8f93\u5165&#xff1a;mat &#061; [[1,2],[3,4]], r &#061; 1, c &#061; 4<br \/>\n\u539f\u77e9\u9635\u662f2\u884c2\u5217&#xff0c;\u603b\u5143\u7d204\u4e2a\u3002\u76ee\u68071\u884c4\u5217&#xff0c;\u603b\u6570\u76f8\u7b49\u3002<br \/>\n\u884c\u904d\u5386\u987a\u5e8f&#xff1a;1, 2, 3, 4<br \/>\n\u8f93\u51fa&#xff1a;[[1,2,3,4]]<\/p>\n<h5>\u793a\u4f8b2<\/h5>\n<p>\u8f93\u5165&#xff1a;mat &#061; [[1,2],[3,4]], r &#061; 2, c &#061; 4<br \/>\n\u539f\u603b\u65704&#xff0c;\u76ee\u6807\u603b\u65708&#xff0c;\u6570\u91cf\u4e0d\u5339\u914d&#xff0c;\u4e0d\u80fd\u91cd\u5851\u3002<br \/>\n\u8f93\u51fa&#xff1a;[[1,2],[3,4]]<\/p>\n<h5>\u7ea6\u675f<\/h5>\n<ul>\n<li>m \u548c n \u7684\u8303\u56f4&#xff1a;1 &lt;&#061; m, n &lt;&#061; 100<\/li>\n<li>r,c \u90fd\u662f\u6b63\u6574\u6570<\/li>\n<\/ul>\n<hr \/>\n<h2>\u8d39\u66fc\u8bb2\u89e3&#xff1a;\u7834\u89e3\u601d\u8def&#xff08;3\u79cd\u89e3\u6cd5&#xff0c;\u4ece\u6700\u7b80\u5355\u5230\u6700\u4f18&#xff09;<\/h2>\n<p>\u8d39\u66fc\u5b66\u4e60\u6cd5&#xff1a;\u628a\u590d\u6742\u95ee\u9898\u62c6\u6210\u666e\u901a\u4eba\u80fd\u542c\u61c2\u7684\u6bd4\u55bb<br \/>\n\u6bd4\u55bb&#xff1a;\u77e9\u9635\u5c31\u50cf\u4e00\u76d2\u6392\u6210\u591a\u884c\u591a\u5217\u7684\u4e52\u4e53\u7403\u3002\u91cd\u5851&#061;\u628a\u6240\u6709\u4e52\u4e53\u7403\u5168\u90e8\u5012\u51fa\u6765\u6392\u6210\u4e00\u6761\u957f\u961f&#xff0c;\u518d\u91cd\u65b0\u88c5\u5230\u65b0\u76d2\u5b50\u91cc\u3002\u53ea\u6709\u4e52\u4e53\u7403\u603b\u6570\u4e00\u6837&#xff0c;\u624d\u80fd\u91cd\u88c5&#xff1b;\u603b\u6570\u4e0d\u4e00\u6837&#xff0c;\u4e0d\u80fd\u91cd\u88c5&#xff0c;\u539f\u6837\u4e0d\u52a8\u3002<\/p>\n<h3>\u6838\u5fc3\u6570\u5b66\u77e5\u8bc6\u70b9&#xff08;\u672c\u9898\u7075\u9b42&#xff09;<\/h3>\n<p>\u5bf9\u4e8e\u4e8c\u7ef4\u77e9\u9635&#xff0c;\u884c\u4f18\u5148\u5c55\u5f00\u6210\u4e00\u7ef4\u5e8f\u53f7 k&#xff08;\u4ece0\u5f00\u59cb&#xff09;<\/p>\n<ul>\n<li>\u539f\u77e9\u9635 m\u884cn\u5217&#xff1a;<br \/>\n\u539f\u884c\u53f7&#xff1a;k \/\/ n &#xff08;\u6574\u6570\u9664\u6cd5&#xff0c;\u5411\u4e0b\u53d6\u6574&#xff09;<br \/>\n\u539f\u5217\u53f7&#xff1a;k % n &#xff08;\u53d6\u4f59\u6570&#xff09;<\/li>\n<li>\u65b0\u77e9\u9635 r\u884cc\u5217&#xff1a;<br \/>\n\u65b0\u884c\u53f7&#xff1a;k \/\/ c<br \/>\n\u65b0\u5217\u53f7&#xff1a;k % c<\/li>\n<\/ul>\n<p>\u4e3e\u4f8b\u5b50&#xff1a;\u539f\u77e9\u96352\u884c2\u5217&#xff0c;k&#061;2<br \/>\nk\/\/n &#061; 2\/\/2 &#061;1 \u7b2c1\u884c&#xff1b;k%n&#061;2%2&#061;0 \u7b2c0\u5217 \u2192 mat[1][0]&#061;3 \u2714<\/p>\n<h3>\u89e3\u6cd51&#xff1a;\u6241\u5e73\u5316\u4e2d\u8f6c\u6cd5&#xff08;\u6700\u5bb9\u6613\u7406\u89e3&#xff0c;\u63a8\u8350\u65b0\u624b&#xff09;<\/h3>\n<p>\u601d\u8def&#xff1a;<\/p>\n<li>\u5148\u7b97\u539f\u77e9\u9635\u603b\u5143\u7d20&#xff0c;\u5bf9\u6bd4\u76ee\u6807\u603b\u6570&#xff1b;\u4e0d\u7b49\u76f4\u63a5\u8fd4\u56de\u539f\u77e9\u9635\u3002<\/li>\n<li>\u904d\u5386\u539f\u77e9\u9635&#xff0c;\u628a\u6240\u6709\u5143\u7d20\u62ff\u51fa\u6765\u653e\u5230\u4e00\u7ef4\u6241\u5e73\u5217\u8868&#xff08;\u4e52\u4e53\u7403\u5168\u90e8\u5012\u6210\u957f\u961f&#xff09;\u3002<\/li>\n<li>\u65b0\u5efa\u7a7ar\u884cc\u5217\u77e9\u9635&#xff0c;\u5faa\u73af\u4f9d\u6b21\u4ece\u4e00\u7ef4\u5217\u8868\u53d6\u5143\u7d20\u586b\u5165\u3002<\/li>\n<h4>Python\u4ee3\u7801&#xff08;\u9010\u884c\u6700\u5927\u6ce8\u91ca&#xff09;<\/h4>\n<p><span class=\"token keyword\">from<\/span> typing <span class=\"token keyword\">import<\/span> List<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Solution<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">matrixReshape<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> mat<span class=\"token punctuation\">:<\/span> List<span class=\"token punctuation\">[<\/span>List<span class=\"token punctuation\">[<\/span><span class=\"token builtin\">int<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> r<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">,<\/span> c<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> List<span class=\"token punctuation\">[<\/span>List<span class=\"token punctuation\">[<\/span><span class=\"token builtin\">int<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token comment\"># mat&#xff1a;\u8f93\u5165\u4e8c\u7ef4\u77e9\u9635&#xff1b;r\u76ee\u6807\u884c\u6570&#xff1b;c\u76ee\u6807\u5217\u6570&#xff1b;\u8fd4\u56de\u91cd\u5851\u540e\u7684\u4e8c\u7ef4\u77e9\u9635<\/span><br \/>\n        <span class=\"token comment\"># \u7b2c\u4e00\u6b65&#xff1a;\u83b7\u53d6\u539f\u77e9\u9635\u884c\u6570 m<\/span><br \/>\n        m <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>mat<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token comment\"># \u83b7\u53d6\u539f\u77e9\u9635\u7b2c0\u884c\u7684\u957f\u5ea6&#xff0c;\u4e5f\u5c31\u662f\u539f\u77e9\u9635\u5217\u6570 n<\/span><br \/>\n        n <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>mat<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\"># \u5224\u65ad\u603b\u5143\u7d20\u6570\u91cf\u662f\u5426\u76f8\u7b49&#xff0c;\u4e0d\u7b49\u76f4\u63a5\u8fd4\u56de\u539f\u77e9\u9635&#xff0c;\u65e0\u6cd5\u91cd\u5851<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> m <span class=\"token operator\">*<\/span> n <span class=\"token operator\">!&#061;<\/span> r <span class=\"token operator\">*<\/span> c<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> mat<\/p>\n<p>        <span class=\"token comment\"># \u521b\u5efa\u4e00\u7ef4\u6241\u5e73\u5217\u8868&#xff0c;\u7528\u6765\u5b58\u653e\u6240\u6709\u5143\u7d20&#xff08;\u628a\u77e9\u9635\u644a\u5e73\u6210\u4e00\u6761\u7ebf&#xff09;<\/span><br \/>\n        flat_list <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><br \/>\n        <span class=\"token comment\"># \u5916\u5c42\u5faa\u73af&#xff1a;\u904d\u5386\u539f\u77e9\u9635\u6bcf\u4e00\u884c<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> row <span class=\"token keyword\">in<\/span> mat<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token comment\"># \u5185\u5c42\u5faa\u73af&#xff1a;\u904d\u5386\u5f53\u524d\u884c\u91cc\u9762\u6bcf\u4e00\u4e2a\u6570\u5b57<\/span><br \/>\n            <span class=\"token keyword\">for<\/span> num <span class=\"token keyword\">in<\/span> row<span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token comment\"># \u5c06\u6570\u5b57\u8ffd\u52a0\u5230\u6241\u5e73\u4e00\u7ef4\u5217\u8868\u5c3e\u90e8<\/span><br \/>\n                flat_list<span class=\"token punctuation\">.<\/span>append<span class=\"token punctuation\">(<\/span>num<span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\"># \u521b\u5efa\u6700\u7ec8\u7ed3\u679c\u4e8c\u7ef4\u5217\u8868<\/span><br \/>\n        result <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><br \/>\n        <span class=\"token comment\"># \u521d\u59cb\u5316\u4e00\u7ef4\u5217\u8868\u7684\u8bfb\u53d6\u6307\u9488&#xff0c;\u4ece\u7b2c0\u4e2a\u5143\u7d20\u5f00\u59cb\u8bfb\u53d6<\/span><br \/>\n        ptr <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><br \/>\n        <span class=\"token comment\"># \u5faa\u73afr\u6b21&#xff0c;\u6bcf\u6b21\u6784\u5efa\u65b0\u77e9\u9635\u7684\u4e00\u884c<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> i <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>r<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token comment\"># \u4e34\u65f6\u5355\u884c\u5217\u8868&#xff0c;\u7528\u6765\u5b58\u653e\u65b0\u77e9\u9635\u5f53\u524d\u884c\u7684c\u4e2a\u5143\u7d20<\/span><br \/>\n            temp_row <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><br \/>\n            <span class=\"token comment\"># \u5faa\u73afc\u6b21&#xff0c;\u586b\u5145\u5f53\u524d\u884c\u6bcf\u4e00\u5217<\/span><br \/>\n            <span class=\"token keyword\">for<\/span> j <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>c<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token comment\"># \u53d6\u51fa\u6241\u5e73\u5217\u8868ptr\u4f4d\u7f6e\u5143\u7d20&#xff0c;\u653e\u5230\u4e34\u65f6\u884c<\/span><br \/>\n                temp_row<span class=\"token punctuation\">.<\/span>append<span class=\"token punctuation\">(<\/span>flat_list<span class=\"token punctuation\">[<\/span>ptr<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><br \/>\n                <span class=\"token comment\"># \u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d&#xff0c;\u51c6\u5907\u8bfb\u53d6\u4e0b\u4e00\u4e2a\u5143\u7d20<\/span><br \/>\n                ptr <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n            <span class=\"token comment\"># \u628a\u6784\u5efa\u5b8c\u6210\u7684\u5355\u884c&#xff0c;\u52a0\u5165\u6700\u7ec8\u7ed3\u679c\u77e9\u9635<\/span><br \/>\n            result<span class=\"token punctuation\">.<\/span>append<span class=\"token punctuation\">(<\/span>temp_row<span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\"># \u8fd4\u56de\u91cd\u5851\u5b8c\u6210\u7684\u77e9\u9635<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> result<\/p>\n<h4>\u8d39\u66fc\u8bb2\u89e3\u89e3\u6cd51<\/h4>\n<p>\u5c31\u50cf\u628a\u76d2\u5b50\u91cc\u6240\u6709\u4e52\u4e53\u7403\u5168\u90e8\u5012\u51fa\u6765\u6392\u6210\u4e00\u961f&#xff0c;\u7136\u540e\u62ff\u65b0\u76d2\u5b50&#xff0c;\u4e00\u884c\u4e00\u884c\u653e\u8fdb\u53bb\u3002<br \/>\n\u4f18\u70b9&#xff1a;\u903b\u8f91\u76f4\u89c2&#xff0c;\u4eba\u8111\u597d\u7406\u89e3&#xff1b;\u7f3a\u70b9&#xff1a;\u591a\u5f00\u4e86\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4&#xff0c;\u989d\u5916\u5360\u7528\u5185\u5b58\u3002\u65f6\u95f4\u590d\u6742\u5ea6 O(m*n)&#xff0c;\u8981\u904d\u5386\u5168\u90e8\u5143\u7d20\u3002<\/p>\n<h3>\u89e3\u6cd52&#xff1a;\u53cc\u5faa\u73af\u904d\u5386&#043;\u5750\u6807\u6307\u9488&#xff08;\u539f\u5730\u586b\u5145&#xff0c;\u4e0d\u644a\u5e73\u6570\u7ec4&#xff09;<\/h3>\n<p>\u601d\u8def&#xff1a;<\/p>\n<li>\u603b\u6570\u6821\u9a8c&#xff0c;\u603b\u6570\u4e0d\u7b49\u8fd4\u56de\u539f\u77e9\u9635\u3002<\/li>\n<li>\u521b\u5efar\u884cc\u5217&#xff0c;\u5168\u90e8\u586b\u51450\u7684\u65b0\u77e9\u9635\u3002<\/li>\n<li>\u53cc\u5faa\u73af\u904d\u5386\u539f\u77e9\u9635\u6bcf\u4e00\u4e2a\u5143\u7d20&#xff0c;\u7528\u4e00\u4e2a\u5168\u5c40\u6307\u9488 k&#xff0c;\u4e0d\u65ad&#043;1\u3002<\/li>\n<li>\u7528 k\/\/c \u7b97\u51fa\u65b0\u77e9\u9635\u884c&#xff0c;k%c\u7b97\u51fa\u65b0\u77e9\u9635\u5217&#xff0c;\u76f4\u63a5\u8d4b\u503c\u3002<\/li>\n<p><span class=\"token keyword\">from<\/span> typing <span class=\"token keyword\">import<\/span> List<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Solution<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">matrixReshape<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> mat<span class=\"token punctuation\">:<\/span> List<span class=\"token punctuation\">[<\/span>List<span class=\"token punctuation\">[<\/span><span class=\"token builtin\">int<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> r<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">,<\/span> c<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> List<span class=\"token punctuation\">[<\/span>List<span class=\"token punctuation\">[<\/span><span class=\"token builtin\">int<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token comment\"># \u83b7\u53d6\u539f\u77e9\u9635\u884c\u6570m<\/span><br \/>\n        m <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>mat<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token comment\"># \u83b7\u53d6\u539f\u77e9\u9635\u5217\u6570n<\/span><br \/>\n        n <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>mat<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\"># \u5143\u7d20\u603b\u6570\u4e0d\u4e00\u81f4&#xff0c;\u65e0\u6cd5\u91cd\u5851&#xff0c;\u8fd4\u56de\u539f\u77e9\u9635<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> m <span class=\"token operator\">*<\/span> n <span class=\"token operator\">!&#061;<\/span> r <span class=\"token operator\">*<\/span> c<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> mat<\/p>\n<p>        <span class=\"token comment\"># \u521b\u5efar\u884cc\u5217\u521d\u59cb\u503c\u51680\u7684\u4e8c\u7ef4\u5217\u8868<\/span><br \/>\n        res <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">*<\/span> c <span class=\"token keyword\">for<\/span> _ <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>r<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">]<\/span><br \/>\n        <span class=\"token comment\"># k\u662f\u5168\u5c40\u4e00\u7ef4\u5e8f\u53f7\u6307\u9488&#xff0c;\u4ece0\u5f00\u59cb\u8ba1\u6570<\/span><br \/>\n        k <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><\/p>\n<p>        <span class=\"token comment\"># \u5916\u5c42\u5faa\u73af\u904d\u5386\u539f\u77e9\u9635\u6bcf\u4e00\u884c<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> i <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>m<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token comment\"># \u5185\u5c42\u5faa\u73af\u904d\u5386\u539f\u77e9\u9635\u5f53\u524d\u884c\u6bcf\u4e00\u5217<\/span><br \/>\n            <span class=\"token keyword\">for<\/span> j <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token comment\"># \u8ba1\u7b97\u5f53\u524d\u5143\u7d20\u5728\u65b0\u77e9\u9635\u7684\u884c\u53f7&#xff1a;k\u6574\u9664c<\/span><br \/>\n                new_row <span class=\"token operator\">&#061;<\/span> k <span class=\"token operator\">\/\/<\/span> c<br \/>\n                <span class=\"token comment\"># \u8ba1\u7b97\u5f53\u524d\u5143\u7d20\u5728\u65b0\u77e9\u9635\u7684\u5217\u53f7&#xff1a;k\u5bf9c\u53d6\u4f59\u6570<\/span><br \/>\n                new_col <span class=\"token operator\">&#061;<\/span> k <span class=\"token operator\">%<\/span> c<br \/>\n                <span class=\"token comment\"># \u5c06\u539f\u77e9\u9635 mat[i][j] \u7684\u503c&#xff0c;\u5199\u5165\u65b0\u77e9\u9635\u5bf9\u5e94\u4f4d\u7f6e<\/span><br \/>\n                res<span class=\"token punctuation\">[<\/span>new_row<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>new_col<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> mat<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span><br \/>\n                <span class=\"token comment\"># \u5e8f\u53f7&#043;1&#xff0c;\u5904\u7406\u4e0b\u4e00\u4e2a\u5143\u7d20<\/span><br \/>\n                k <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token number\">1<\/span><\/p>\n<p>        <span class=\"token keyword\">return<\/span> res<\/p>\n<p>\u8d39\u66fc\u8bb2\u89e3\u89e3\u6cd52&#xff1a;\u4e0d\u5012\u51fa\u4e52\u4e53\u7403&#xff0c;\u4e00\u8fb9\u8bfb\u65e7\u76d2\u5b50&#xff0c;\u4e00\u8fb9\u5f80\u65b0\u76d2\u5b50\u91cc\u9762\u653e&#xff0c;\u53ea\u9700\u8981\u4e00\u4e2a\u8ba1\u6570\u5668\u6807\u8bb0\u8fd9\u662f\u7b2c\u51e0\u4e2a\u7403\u3002\u8282\u7701\u4e86\u4e00\u7ef4\u6570\u7ec4\u7a7a\u95f4\u3002<\/p>\n<h3>\u89e3\u6cd53&#xff1a;\u6570\u5b66\u7d22\u5f15\u6620\u5c04\u6700\u4f18\u5355\u5faa\u73af&#xff08;\u63a8\u8350\u9762\u8bd5\u5199&#xff09;<\/h3>\n<p>\u6700\u4f18\u5199\u6cd5&#xff1a;\u53ea\u7528\u4e00\u5c42\u5faa\u73af&#xff0c;\u76f4\u63a5\u7528\u4e00\u7ef4\u5e8f\u53f7k\u540c\u65f6\u6620\u5c04\u539f\u77e9\u9635\u5750\u6807\u3001\u65b0\u77e9\u9635\u5750\u6807&#xff0c;\u4ee3\u7801\u6700\u7b80\u6d01\u3002\u9762\u8bd5\u9996\u9009\u3002<\/p>\n<p><span class=\"token keyword\">from<\/span> typing <span class=\"token keyword\">import<\/span> List<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Solution<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">matrixReshape<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> mat<span class=\"token punctuation\">:<\/span> List<span class=\"token punctuation\">[<\/span>List<span class=\"token punctuation\">[<\/span><span class=\"token builtin\">int<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> r<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">,<\/span> c<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> List<span class=\"token punctuation\">[<\/span>List<span class=\"token punctuation\">[<\/span><span class=\"token builtin\">int<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token comment\"># m&#xff1a;\u539f\u77e9\u9635\u884c\u6570<\/span><br \/>\n        m <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>mat<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token comment\"># n&#xff1a;\u539f\u77e9\u9635\u5217\u6570<\/span><br \/>\n        n <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>mat<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\"># \u603b\u6570\u6821\u9a8c&#xff0c;\u6570\u91cf\u4e0d\u4e00\u81f4\u76f4\u63a5\u8fd4\u56de\u539f\u77e9\u9635<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> m <span class=\"token operator\">*<\/span> n <span class=\"token operator\">!&#061;<\/span> r <span class=\"token operator\">*<\/span> c<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> mat<\/p>\n<p>        <span class=\"token comment\"># \u521d\u59cb\u5316r\u884cc\u5217\u51680\u77e9\u9635<\/span><br \/>\n        res <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">*<\/span> c <span class=\"token keyword\">for<\/span> _ <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>r<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">]<\/span><\/p>\n<p>        <span class=\"token comment\"># \u4e00\u7ef4\u5e8f\u53f7k\u4ece0\u904d\u5386\u5230\u603b\u5143\u7d20mn-1&#xff0c;\u4e00\u5c42\u5faa\u73af\u641e\u5b9a<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> k <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>m <span class=\"token operator\">*<\/span> n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token comment\"># \u539f\u77e9\u9635\u884c&#xff1a;k\u9664\u4ee5\u539f\u5217\u6570n&#xff0c;\u6574\u6570\u9664\u6cd5<\/span><br \/>\n            old_row <span class=\"token operator\">&#061;<\/span> k <span class=\"token operator\">\/\/<\/span> n<br \/>\n            <span class=\"token comment\"># \u539f\u77e9\u9635\u5217&#xff1a;k\u5bf9\u539f\u5217\u6570n\u53d6\u6a21<\/span><br \/>\n            old_col <span class=\"token operator\">&#061;<\/span> k <span class=\"token operator\">%<\/span> n<\/p>\n<p>            <span class=\"token comment\"># \u65b0\u77e9\u9635\u884c&#xff1a;k\u9664\u4ee5\u76ee\u6807\u5217\u6570c&#xff0c;\u6574\u6570\u9664\u6cd5<\/span><br \/>\n            new_row <span class=\"token operator\">&#061;<\/span> k <span class=\"token operator\">\/\/<\/span> c<br \/>\n            <span class=\"token comment\"># \u65b0\u77e9\u9635\u5217&#xff1a;k\u5bf9\u76ee\u6807\u5217\u6570c\u53d6\u6a21<\/span><br \/>\n            new_col <span class=\"token operator\">&#061;<\/span> k <span class=\"token operator\">%<\/span> c<\/p>\n<p>            <span class=\"token comment\"># \u5143\u7d20\u62f7\u8d1d<\/span><br \/>\n            res<span class=\"token punctuation\">[<\/span>new_row<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>new_col<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> mat<span class=\"token punctuation\">[<\/span>old_row<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>old_col<span class=\"token punctuation\">]<\/span><\/p>\n<p>        <span class=\"token keyword\">return<\/span> res<\/p>\n<p>\u8d39\u66fc\u8bb2\u89e3\u89e3\u6cd53&#xff1a;<br \/>\n\u60f3\u8c61\u6240\u6709\u4e52\u4e53\u7403\u7f16\u53f70\u30011\u30012\u30013\u2026\u2026\u3002\u4e0d\u7ba1\u65e7\u76d2\u5b50\u8fd8\u662f\u65b0\u76d2\u5b50&#xff0c;\u540c\u4e00\u4e2a\u7f16\u53f7\u7684\u7403&#xff0c;\u90fd\u53ef\u4ee5\u901a\u8fc7\u300c\u6574\u9664\u884c\u6570\u3001\u53d6\u4f59\u5217\u6570\u300d\u7b97\u51fa\u5b83\u5728\u76d2\u5b50\u91cc\u7684\u4f4d\u7f6e\u3002\u4e0d\u9700\u8981\u4e24\u5c42\u5faa\u73af&#xff0c;\u4e00\u4e2a\u5faa\u73af\u5c31\u80fd\u5b8c\u6210\u6620\u5c04\u3002<br \/>\n\u65f6\u95f4\u590d\u6742\u5ea6 O(mn)&#xff0c;\u7a7a\u95f4 O(r*c)&#xff08;\u8f93\u51fa\u77e9\u9635\u5fc5\u987b\u5360\u7528&#xff0c;\u4e0d\u7b97\u989d\u5916\u5f00\u9500&#xff09;\u3002<\/p>\n<hr \/>\n<h2>\u5e94\u7528\u573a\u666f\u4e3e\u4f8b<\/h2>\n<li>\u56fe\u50cf\u5904\u7406&#xff1a;\u56fe\u50cf\u672c\u8d28\u662f\u4e8c\u7ef4\u50cf\u7d20\u77e9\u9635\u3002\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u7ecf\u5e38\u9700\u8981\u628a\u56fe\u7247\u77e9\u9635\u91cd\u5851&#xff08;reshape&#xff09;&#xff0c;\u6bd4\u5982\u628a 28\u00d728 \u7684\u7070\u5ea6\u56fe\u91cd\u5851\u6210 1\u00d7784 \u7684\u4e00\u7ef4\u5411\u91cf&#xff0c;\u9001\u5165\u795e\u7ecf\u7f51\u7edc\u3002<\/li>\n<li>\u6570\u636e\u5206\u6790&#xff1a;Pandas \/ Numpy \u4e2d reshape&#xff0c;\u8868\u683c\u6570\u636e\u7ef4\u5ea6\u8f6c\u6362\u3002\u6bd4\u5982\u91c7\u96c6\u6570\u636e\u662f\u591a\u884c\u591a\u5217&#xff0c;\u9700\u8981\u6539\u6210\u4e00\u884c\u5411\u91cf\u505a\u7279\u5f81\u8f93\u5165\u3002<\/li>\n<li>\u4f20\u611f\u5668\u6570\u636e&#xff1a;\u8bbe\u5907\u91c7\u96c610\u884c10\u5217\u4f20\u611f\u5668\u6570\u636e&#xff0c;\u9700\u8981\u6539\u62105\u884c20\u5217\u77e9\u9635&#xff0c;\u65b9\u4fbf\u7ed8\u56fe\u5c55\u793a\u3002<\/li>\n<li>\u6e38\u620f\u5f00\u53d1&#xff1a;\u5730\u56fe\u7f51\u683c\u77e9\u9635\u91cd\u5851&#xff0c;\u628a\u5c0f\u5730\u56fe\u4e8c\u7ef4\u7f51\u683c\u91cd\u65b0\u6392\u5e03\u3002<\/li>\n<p>\u8fd9\u4e2aLeetCode\u9898\u76ee\u672c\u8d28\u5c31\u662f\u590d\u523b Numpy \/ MATLAB \u7684 reshape \u5e95\u5c42\u903b\u8f91\u3002<\/p>\n<h2>\u6d4b\u8bd5\u4ee3\u7801&#xff08;\u76f4\u63a5\u8fd0\u884c\u9a8c\u8bc1&#xff09;<\/h2>\n<p><span class=\"token comment\"># \u6d4b\u8bd5\u6837\u4f8b1<\/span><br \/>\nsol <span class=\"token operator\">&#061;<\/span> Solution<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\nmat1 <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>sol<span class=\"token punctuation\">.<\/span>matrixReshape<span class=\"token punctuation\">(<\/span>mat1<span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\"># [[1,2,3,4]]<\/span><\/p>\n<p><span class=\"token comment\"># \u6d4b\u8bd5\u6837\u4f8b2<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>sol<span class=\"token punctuation\">.<\/span>matrixReshape<span class=\"token punctuation\">(<\/span>mat1<span class=\"token punctuation\">,<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\"># [[1,2],[3,4]]<\/span><\/p>\n<h2>\u8d39\u66fc\u81ea\u68c0&#xff08;\u4f60\u80fd\u4e0d\u80fd\u8bb2\u51fa\u6765&#xff1f;&#xff09;<\/h2>\n<li>\u4ec0\u4e48\u65f6\u5019\u4e0d\u80fd\u91cd\u5851&#xff1f;\u2705 \u5143\u7d20\u603b\u6570\u4e0d\u4e00\u6837<\/li>\n<li>k\/\/n \u548c k%n \u5206\u522b\u4ee3\u8868\u4ec0\u4e48&#xff1f;\u2705 \u884c\u53f7\u3001\u5217\u53f7<\/li>\n<li>\u4e09\u79cd\u65b9\u6848\u4f18\u7f3a\u70b9&#xff1f;\u2705 \u644a\u5e73\u6cd5\u597d\u61c2&#xff1b;\u53cc\u5faa\u73af\u7701\u7a7a\u95f4&#xff1b;\u5355\u5faa\u73af\u4ee3\u7801\u7b80\u6d01\u9762\u8bd5\u9996\u9009<\/li>\n","protected":false},"excerpt":{"rendered":"<p>LeetCode 566&#xff5c;\u91cd\u5851\u77e9\u9635 Reshape the Matrix\u8d39\u66fc\u5b66\u4e60\u6cd5\u6838\u5fc3\u601d\u8def&#xff1a;\u4e0d\u7528\u672f\u8bed&#xff0c;\u7528\u5927\u767d\u8bdd\u8bb2\u6e05\u695a&#xff0c;\u5047\u8bbe\u4f60\u8981\u8bb2\u7ed9\u4e00\u4e2a\u5c0f\u767d\u542c\u61c2&#xff1b;\u5148\u660e\u767d\u95ee\u9898\u672c\u8d28&#xff0c;\u518d\u601d\u8003\u65b9\u6848&#xff0c;\u6700\u540e\u5199\u4ee3\u7801&#xff0c;\u6bcf\u884c\u52a0\u8be6\u7ec6\u6ce8\u91ca\u9898\u76ee\u4fe1\u606f<br \/>\n\u9898\u53f7&#xff1a;566<br \/>\n\u9898\u76ee\u540d\u79f0&#xff1a;\u91cd\u5851\u77e9\u9635 Reshape the Matrix<br \/>\n\u96be\u5ea6&#xff1a;\u7b80\u5355<br \/>\n\u6807\u7b7e&#xff1a;\u6570\u7ec4\u3001\u77e9\u9635\u3001\u6a21<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2692,1578,427],"topic":[],"class_list":["post-103875","post","type-post","status-publish","format-standard","hentry","category-server","tag-leetcode","tag-1578","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>LeetCode 566\uff5c\u91cd\u5851\u77e9\u9635 Reshape the Matrix - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/103875.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LeetCode 566\uff5c\u91cd\u5851\u77e9\u9635 Reshape the Matrix - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"LeetCode 566&#xff5c;\u91cd\u5851\u77e9\u9635 Reshape the Matrix\u8d39\u66fc\u5b66\u4e60\u6cd5\u6838\u5fc3\u601d\u8def&#xff1a;\u4e0d\u7528\u672f\u8bed&#xff0c;\u7528\u5927\u767d\u8bdd\u8bb2\u6e05\u695a&#xff0c;\u5047\u8bbe\u4f60\u8981\u8bb2\u7ed9\u4e00\u4e2a\u5c0f\u767d\u542c\u61c2&#xff1b;\u5148\u660e\u767d\u95ee\u9898\u672c\u8d28&#xff0c;\u518d\u601d\u8003\u65b9\u6848&#xff0c;\u6700\u540e\u5199\u4ee3\u7801&#xff0c;\u6bcf\u884c\u52a0\u8be6\u7ec6\u6ce8\u91ca\u9898\u76ee\u4fe1\u606f \u9898\u53f7&#xff1a;566 \u9898\u76ee\u540d\u79f0&#xff1a;\u91cd\u5851\u77e9\u9635 Reshape the Matrix \u96be\u5ea6&#xff1a;\u7b80\u5355 \u6807\u7b7e&#xff1a;\u6570\u7ec4\u3001\u77e9\u9635\u3001\u6a21\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/103875.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-11T05:17:28+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/103875.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/103875.html\",\"name\":\"LeetCode 566\uff5c\u91cd\u5851\u77e9\u9635 Reshape the Matrix - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-11T05:17:28+00:00\",\"dateModified\":\"2026-09-11T05:17:28+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/103875.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/103875.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/103875.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LeetCode 566\uff5c\u91cd\u5851\u77e9\u9635 Reshape the Matrix\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LeetCode 566\uff5c\u91cd\u5851\u77e9\u9635 Reshape the Matrix - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/103875.html","og_locale":"zh_CN","og_type":"article","og_title":"LeetCode 566\uff5c\u91cd\u5851\u77e9\u9635 Reshape the Matrix - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"LeetCode 566&#xff5c;\u91cd\u5851\u77e9\u9635 Reshape the Matrix\u8d39\u66fc\u5b66\u4e60\u6cd5\u6838\u5fc3\u601d\u8def&#xff1a;\u4e0d\u7528\u672f\u8bed&#xff0c;\u7528\u5927\u767d\u8bdd\u8bb2\u6e05\u695a&#xff0c;\u5047\u8bbe\u4f60\u8981\u8bb2\u7ed9\u4e00\u4e2a\u5c0f\u767d\u542c\u61c2&#xff1b;\u5148\u660e\u767d\u95ee\u9898\u672c\u8d28&#xff0c;\u518d\u601d\u8003\u65b9\u6848&#xff0c;\u6700\u540e\u5199\u4ee3\u7801&#xff0c;\u6bcf\u884c\u52a0\u8be6\u7ec6\u6ce8\u91ca\u9898\u76ee\u4fe1\u606f \u9898\u53f7&#xff1a;566 \u9898\u76ee\u540d\u79f0&#xff1a;\u91cd\u5851\u77e9\u9635 Reshape the Matrix \u96be\u5ea6&#xff1a;\u7b80\u5355 \u6807\u7b7e&#xff1a;\u6570\u7ec4\u3001\u77e9\u9635\u3001\u6a21","og_url":"https:\/\/www.wsisp.com\/helps\/103875.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-11T05:17:28+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/103875.html","url":"https:\/\/www.wsisp.com\/helps\/103875.html","name":"LeetCode 566\uff5c\u91cd\u5851\u77e9\u9635 Reshape the Matrix - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-11T05:17:28+00:00","dateModified":"2026-09-11T05:17:28+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/103875.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/103875.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/103875.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"LeetCode 566\uff5c\u91cd\u5851\u77e9\u9635 Reshape the Matrix"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/103875","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=103875"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/103875\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=103875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=103875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=103875"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=103875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}