{"id":161324,"date":"2020-09-09T16:50:00","date_gmt":"2020-09-09T08:50:00","guid":{"rendered":"http:\/\/4563.org\/?p=161324"},"modified":"2020-09-09T16:50:00","modified_gmt":"2020-09-09T08:50:00","slug":"%e6%90%9c%e7%b4%a2%e4%ba%8c%e7%bb%b4%e7%9f%a9%e9%98%b5","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=161324","title":{"rendered":"\u641c\u7d22\u4e8c\u7ef4\u77e9\u9635"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u641c\u7d22\u4e8c\u7ef4\u77e9\u9635               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzzrf <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5199\u51fa\u4e00\u4e2a\u9ad8\u6548\u7684\u7b97\u6cd5\u6765\u641c\u7d22 m \u00d7 n \u77e9\u9635\u4e2d\u7684\u503c\u3002 \u8fd9\u4e2a\u77e9\u9635\u5177\u6709\u4ee5\u4e0b\u7279\u6027\uff1a<\/p>\n<ul>\n<li>\u6bcf\u884c\u4e2d\u7684\u6574\u6570\u4ece\u5de6\u5230\u53f3\u662f\u6392\u5e8f\u7684\u3002<\/li>\n<li>\u6bcf\u884c\u7684\u7b2c\u4e00\u4e2a\u6570\u5927\u4e8e\u4e0a\u4e00\u884c\u7684\u6700\u540e\u4e00\u4e2a\u6574\u6570\u3002<\/li>\n<\/ul>\n<p>\u5728\u7ebf\u505a\u9898\u5730\u5740<\/p>\n<h2>\u6837\u4f8b 1:<\/h2>\n<pre><code>\u8f93\u5165: [[5]],2 \u8f93\u51fa: false          \u6837\u4f8b\u89e3\u91ca:  \u6ca1\u6709\u5305\u542b\uff0c\u8fd4\u56de false \u3002 <\/code><\/pre>\n<h2>\u6837\u4f8b 2:<\/h2>\n<pre><code>\u8f93\u5165:   [   [1, 3, 5, 7],   [10, 11, 16, 20],   [23, 30, 34, 50] ],3  \u8f93\u51fa: true          \u6837\u4f8b\u89e3\u91ca:  \u5305\u542b\u5219\u8fd4\u56de true \u3002 <\/code><\/pre>\n<h2>\u89e3\u9898\u601d\u8def\uff1a<\/h2>\n<p>\u9898\u76ee\u63d0\u5230\uff0c\u7ed9\u5b9a\u7684\u6570\u7ec4\u5df2\u7ecf\u6392\u5e8f\uff0c\u82e5\u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff0c\u76f4\u63a5\u4e00\u6b21\u4e8c\u5206\u67e5\u627e\u5373\u53ef\u3002\u73b0\u5728\u9898\u76ee\u7ed9\u4e86\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\uff0c\u90a3\u4e48\u5904\u7406\u4e00\u4e0b\u6570\u7ec4\u7684\u4e0b\u6807\uff0c\u4ecd\u7136\u6309\u7167\u4e00\u7ef4\u6570\u7ec4\u4e8c\u5206\u5373\u53ef\u3002<\/p>\n<p>\u4e8c\u5206\u67e5\u627e\u5e38\u7528\u4e8e\u67e5\u627e\u6709\u5e8f\u6570\u7ec4\u4e2d\u76ee\u6807\u6570 target \u7684\u4f4d\u7f6e\uff0c\u7528 left \u548c right \u8bb0\u5f55 target \u6240\u5728\u7684\u533a\u95f4\u7aef\u70b9\uff0c\u6bcf\u6b21\u5c06\u533a\u95f4\u7684\u4e2d\u95f4\u4f4d\u7f6e\u503c\u548c target \u4f5c\u6bd4\u8f83\uff0c\u7136\u540e\u79fb\u52a8\u533a\u95f4\u7aef\u70b9\u3002<\/p>\n<h2>\u7b97\u6cd5\u6d41\u7a0b\uff1a<\/h2>\n<ul>\n<li>\u5c06\u6570\u7ec4 matrix[i][j]\u4e0b\u6807\u8f6c\u6362\u4e3a i*col + j\uff0c \u95ee\u9898\u5373\u8f6c\u6362\u4e3a\u4e00\u7ef4\u6570\u7ec4\u4e8c\u5206\u67e5\u627e\u95ee\u9898<\/li>\n<li>\u5c06\u533a\u95f4\u8d4b\u503c\u4e3a\u6574\u4e2a\u6570\u7ec4\u533a\u95f4\uff08 left = 0, right = n*m &#8211; 1 \uff09\uff0c\u53d6\u4e2d\u95f4\u4f4d\u7f6e mid<\/li>\n<li>\u82e5 a[mid] &lt; target\uff0c\u5219\u5c06\u533a\u95f4\u7f29\u5c0f\u5230\u539f\u533a\u95f4\u7684\u53f3\u533a\u95f4(left = mid + 1)<\/li>\n<li>\u82e5 a[mid] &gt; target\uff0c\u5219\u5c06\u533a\u95f4\u7f29\u5c0f\u81f3\u539f\u533a\u95f4\u7684\u5de6\u533a\u95f4(right = mid)<\/li>\n<li>\u82e5 a[mid] = target\uff0c\u8fd4\u56de true<\/li>\n<li>\u5f53 left &gt;= right \u65f6\uff0c\u82e5 a[right] = target \u5219\u8fd4\u56de true, \u5426\u5219\u8fd4\u56de false<\/li>\n<\/ul>\n<h2>\u590d\u6742\u5ea6\u5206\u6790\uff1a<\/h2>\n<ul>\n<li>\u65f6\u95f4\u590d\u6742\u5ea6\uff1aO(log(nm))<\/li>\n<li>\u5373\u5c06\u4e8c\u7ef4\u6570\u7ec4\u770b\u4f5c\u4e00\u4e2a n*m \u5927\u5c0f\u7684\u4e00\u7ef4\u6570\u7ec4\uff0c\u4e8c\u5206\u67e5\u627e\u503c\u3002<\/li>\n<li>\u7a7a\u95f4\u590d\u6742\u5ea6\uff1aO(1)<\/li>\n<li>\u67e5\u627e\u4e0d\u9700\u8981\u5f00\u8f9f\u65b0\u7684\u7a7a\u95f4\uff0c\u53ea\u9700\u5728\u539f\u6570\u7ec4\u57fa\u7840\u4e0a\u8fdb\u884c\u67e5\u627e\u5373\u53ef<\/li>\n<\/ul>\n<h2>\u4ee3\u7801\uff1a<\/h2>\n<pre><code>public class Solution {     \/**      * @param matrix, a list of lists of integers      * @param target, an integer      * @return a boolean, indicate whether matrix contains target      *\/     public boolean searchMatrix(int[][] matrix, int target) {         int n = matrix.length;         int col = matrix[0].length;         int left = 0, right = n*col - 1;                  while(left &lt; right){             int mid = (right + left) \/ 2;             if(matrix[mid\/col][mid%col] == target){                 return true;             }             else if(matrix[mid\/col][mid%col] &gt; target){                 right = mid;             }             else{                 left = mid + 1;             }         }                  if(matrix[right\/col][right%col] == target){             return true;         }                  return false;     } } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u641c\u7d22\u4e8c\u7ef4\u77e9\u9635 \u8cc7\u6df1\u5927\u4f6c : zzz&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/161324"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=161324"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/161324\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=161324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=161324"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=161324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}