{"id":134,"date":"2025-09-16T16:20:29","date_gmt":"2025-09-16T08:20:29","guid":{"rendered":"https:\/\/www.xunfen.cloud\/?p=134"},"modified":"2025-09-16T16:20:29","modified_gmt":"2025-09-16T08:20:29","slug":"%e3%80%90%e7%ac%94%e8%ae%b0%e3%80%91%e5%87%a0%e4%b8%aa%e5%85%b3%e4%ba%8e%e6%8e%92%e5%ba%8f%e4%b8%8e%e6%9f%a5%e6%89%be%e7%9a%84%e7%ae%97%e6%b3%95%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.xunfen.cloud\/?p=134","title":{"rendered":"\u3010\u7b14\u8bb0\u3011\u51e0\u4e2a\u5173\u4e8e\u6392\u5e8f\u4e0e\u67e5\u627e\u7684\u7b97\u6cd5\uff08\u4e00\uff09"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u4e00.\u67e5\u627e<\/h1>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\">1.\u57fa\u672c\u67e5\u627e<\/h3>\n\n\n\n<p>\u4ece0\u7d22\u5f15\u5f00\u59cb\u6328\u4e2a\u5f80\u540e\u67e5\u627e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class BasicSearchDemo1 {\n    public static void main(String&#91;] args) {\n        \/\/\u57fa\u672c\u67e5\u627e\uff1a\u4ece0\u7d22\u5f15\u5f00\u59cb\u6328\u4e2a\u5f80\u540e\u67e5\u627e\n        int&#91;] arr = {131, 127, 147, 81, 103, 23, 7, 79};\n        int target = 17;\n        System.out.println(search(arr, target));\n\n    }\n\n    public static boolean search(int&#91;] arr, int target) {\n        for (int i = 0; i &lt; arr.length; i++) {\n            if (arr&#91;i] == target) {\n                return true;\n            }\n        }\n        return false;\n    }\n    \n}<\/code><\/pre>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\">2.\u4e8c\u5206\u67e5\u627e\/\u6298\u534a\u67e5\u627e<\/h3>\n\n\n\n<p>\u524d\u63d0\u6761\u4ef6\uff1a\u6570\u7ec4\u4e2d\u7684\u6570\u636e\u5fc5\u987b\u662f\u6709\u5e8f\u7684\uff0c\u53ef\u4ee5\u662f\u4ece\u5c0f\u5230\u5927\uff0c\u4e5f\u53ef\u4ee5\u662f\u4ece\u5927\u5230\u5c0f\uff0c\u4f46\u662f\u4e0d\u80fd\u662f\u4e71\u7684<\/p>\n\n\n\n<p>\u6838\u5fc3\u903b\u8f91\uff1a\u6bcf\u6b21\u90fd\u4f1a\u6392\u9664\u4e00\u534a\u7684\u67e5\u627e\u8303\u56f4<\/p>\n\n\n\n<p>\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>1.\u5f97\u5230\u6570\u7ec4\u7684\u5de6\u53f3\u8fb9\u754c\uff08min\uff0cmax\uff09<\/li>\n\n\n\n<li>2.\u5f97\u5230\u4e2d\u95f4\u503c(min+max)\/2        \/\/\u5982\u679c\u8ba1\u7b97\u503c\u4e3a\u5c0f\u6570\u5219\u4ec5\u53d6\u6574\u6570\u90e8\u5206<\/li>\n\n\n\n<li>3.\u6bd4\u8f83\u4e2d\u95f4\u503c\u4e0e\u76ee\u6807\u503c\u5927\u5c0f\uff0c\u786e\u5b9a\u67e5\u627e\u8303\u56f4<\/li>\n\n\n\n<li>4.\u5faa\u73af2-3\uff0c\u76f4\u81f3min >= max\uff08\u6b32\u67e5\u627e\u503c\u4e0d\u518d\u6570\u7ec4\u8303\u56f4\u5185\uff09\u6216min == target\uff08\u67e5\u627e\u5230\u76ee\u6807\u503c\uff09\uff0c\u8df3\u51fa\u5faa\u73af\u5e76\u8fd4\u56de\u7d22\u5f15<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>public class BinarySearchDemo1 {\n    public static void main(String&#91;] args) {\n        \/\/\u4e8c\u5206\u67e5\u627e\uff1a1.\u6570\u7ec4\u5fc5\u987b\u662f\u6709\u5e8f\u7684\n        int&#91;] arr = {1, 8, 10, 89, 1000, 1000, 1234};\/\/\u5b9a\u4e49\u6570\u7ec4\n        int target = 89;\/\/\u786e\u5b9a\u76ee\u6807\u503c\n        int index = binarySearch(arr, target);\/\/\u4ea4\u7ed9\u65b9\u6cd5\u6765\u5904\u7406\n        System.out.println(index);\n\n    }\n\n    public static int binarySearch(int&#91;] arr, int target) {\n        \/\/\u786e\u5b9a\u5de6\u53f3\u8fb9\u754c\n        int min = 0;\/\/\u5b9a\u4e49min\n        int max = arr.length - 1;\/\/\u5b9a\u4e49max\n\n        \/\/\u5faa\u73af\u5224\u65ad\n        while (true) {\n            if (min > max) {\/\/\u4f46min>max\u65f6\uff0c\u8bf4\u660e\u6b32\u67e5\u627e\u503c\u4e0d\u5728\u6570\u7ec4\u5185\n                return -1;\/\/\u8fd4\u56de-1\u9519\u8bef\u503c\n            }\n\n            int mid = (min + max) \/ 2;\/\/\u786e\u5b9a\u4e2d\u95f4\u503c\n            if (arr&#91;mid] > target) {\/\/\u5982\u679c\u4e2d\u95f4\u503cmid\u5927\u4e8e\u76ee\u6807\u503c\uff0c\u786e\u5b9a\u67e5\u627e\u8303\u56f4\u4e3a\u5de6\n                max = mid - 1;\/\/\u91cd\u65b0\u5b9a\u4e49max\n            } else if (arr&#91;mid] &lt; target) {\/\/\u53cd\u4e4b\u786e\u5b9a\u67e5\u627e\u8303\u56f4\u4e3a\u53f3\n                min = mid + 1;\/\/\u91cd\u65b0\u5b9a\u4e49min\n            } else {\/\/\u5269\u4e0b\u4e2d\u95f4\u503c\u7b49\u4e8e\u76ee\u6807\u503c\uff0c\u8fd4\u56de\u4e2d\u95f4\u503c\u7d22\u5f15\uff0c\u4ee3\u8868\u67e5\u627e\u6210\u529f\n                return mid;\n            }\n\n            \/\/\u4ee5\u4e0a\u91cd\u65b0\u5b9a\u4e49min\/max\u540e\u8fdb\u5165\u4e0b\u4e00\u4e2a\u5faa\u73af\u4f1a\u628a\u65b0\u7684max\u4e0emin\u503c\u4ea4\u7531\u65b0\u7684\u5faa\u73af\uff0c\u7136\u540e\u91cd\u65b0\u8ba1\u7b97mid\u503c\u518d\u6b21\u7f29\u5c0f\u8303\u56f4\n        }\n    }\n    \n}\n<\/code><\/pre>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\">3.\u63d2\u503c\u67e5\u627e\/\u6590\u6ce2\u90a3\u5951\u67e5\u627e<\/h3>\n\n\n\n<p>\u5bf9\u4e8e\u63d2\u503c\u67e5\u627e\u4e0e\u6590\u6ce2\u90a3\u5951\u67e5\u627e\uff0c\u4e2a\u4eba\u89c1\u89e3\u662f\u4ed6\u4eec\u662f\u7279\u6b8a\u7684\u4e8c\u5206\u67e5\u627e\uff0c\u53ea\u4e0d\u8fc7\u4e8c\u5206\u67e5\u627e\u662f\u53d6\u4e2d\u95f4\u503cmid\uff0c\u800c\u4ed6\u4eec\u4e8c\u8005\u662f\u6839\u636e\u6b32\u67e5\u627e\u503c\u4e8e\u6570\u7ec4\u5185\u7684\u4f4d\u7f6e\u53d6\u7279\u6b8a\u7684\u201c\u4e2d\u95f4\u503c\u201d<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u63d2\u503c\u67e5\u627e<\/h4>\n\n\n\n<p>\u6838\u5fc3\u516c\u5f0f\uff1a<\/p>\n\n\n\n<p><strong><code>mid = left + ((target - arr[left]) * (right - left)) \/\/ (arr[right] - arr[left])<\/code><\/strong><\/p>\n\n\n\n<p>\u516c\u5f0f\u89e3\u91ca\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>left<\/code>\uff1a\u5f53\u524d\u641c\u7d22\u8303\u56f4\u7684\u5de6\u8fb9\u754c<\/li>\n\n\n\n<li><code>right<\/code>\uff1a\u5f53\u524d\u641c\u7d22\u8303\u56f4\u7684\u53f3\u8fb9\u754c<\/li>\n\n\n\n<li><code>target<\/code>\uff1a\u8981\u67e5\u627e\u7684\u76ee\u6807\u503c<\/li>\n\n\n\n<li><code>arr[left]<\/code>\uff1a\u5de6\u8fb9\u754c\u5904\u7684\u5143\u7d20\u503c<\/li>\n\n\n\n<li><code>arr[right]<\/code>\uff1a\u53f3\u8fb9\u754c\u5904\u7684\u5143\u7d20\u503c<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u6590\u6ce2\u90a3\u5951\u67e5\u627e<\/h4>\n\n\n\n<p>\u4ee51\uff1a0.618\u7684\u65b9\u5f0f\u53d6\u4e2d\u95f4\u503c\uff0cmid=min+\u9ec4\u91d1\u5206\u5272\u70b9\u5de6\u534a\u8fb9\u957f\u5ea6<\/p>\n\n\n\n<p>\u6545\u4e8c\u8005\u4f7f\u7528\u4e00\u4efd\u793a\u4f8b\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class FeiBoSearchDemo {\n    public static int maxSize = 20;\n\n    public static void main(String&#91;] args) {\n        int&#91;] arr = {1, 8, 10, 89, 1000, 1234};\n        System.out.println(search(arr, 1234));\n    }\n\n    public static int&#91;] getFeiBo() {\n        int&#91;] arr = new int&#91;maxSize];\n        arr&#91;0] = 1;\n        arr&#91;1] = 1;\n        for (int i = 2; i &lt; maxSize; i++) {\n            arr&#91;i] = arr&#91;i - 1] + arr&#91;i - 2];\n        }\n        return arr;\n    }\n\n    public static int search(int&#91;] arr, int key) {\n        int low = 0;\n        int high = arr.length - 1;\n        \/\/\u8868\u793a\u6590\u6ce2\u90a3\u5951\u6570\u5206\u5272\u6570\u7684\u4e0b\u6807\u503c\n        int index = 0;\n        int mid = 0;\n        \/\/\u8c03\u7528\u6590\u6ce2\u90a3\u5951\u6570\u5217\n        int&#91;] f = getFeiBo();\n        \/\/\u83b7\u53d6\u6590\u6ce2\u90a3\u5951\u5206\u5272\u6570\u503c\u7684\u4e0b\u6807\n        while (high > (f&#91;index] - 1)) {\n            index++;\n        }\n        \/\/\u56e0\u4e3af&#91;k]\u503c\u53ef\u80fd\u5927\u4e8ea\u7684\u957f\u5ea6\uff0c\u56e0\u6b64\u9700\u8981\u4f7f\u7528Arrays\u5de5\u5177\u7c7b\uff0c\u6784\u9020\u4e00\u4e2a\u65b0\u6cd5\u6570\u7ec4\uff0c\u5e76\u6307\u5411temp&#91;],\u4e0d\u8db3\u7684\u90e8\u5206\u4f1a\u4f7f\u75280\u8865\u9f50\n        int&#91;] temp = Arrays.copyOf(arr, f&#91;index]);\n        \/\/\u5b9e\u9645\u9700\u8981\u4f7f\u7528arr\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u6570\u6765\u586b\u5145\u4e0d\u8db3\u7684\u90e8\u5206\n        for (int i = high + 1; i &lt; temp.length; i++) {\n            temp&#91;i] = arr&#91;high];\n        }\n        \/\/\u4f7f\u7528while\u5faa\u73af\u5904\u7406\uff0c\u627e\u5230key\u503c\n        while (low &lt;= high) {\n            mid = low + f&#91;index - 1] - 1;\n            if (key &lt; temp&#91;mid]) {\/\/\u5411\u6570\u7ec4\u7684\u524d\u9762\u90e8\u5206\u8fdb\u884c\u67e5\u627e\n                high = mid - 1;\n                \/*\n                  \u5bf9k--\u8fdb\u884c\u7406\u89e3\n                  1.\u5168\u90e8\u5143\u7d20=\u524d\u9762\u7684\u5143\u7d20+\u540e\u9762\u7684\u5143\u7d20\n                  2.f&#91;k]=k&#91;k-1]+f&#91;k-2]\n                  \u56e0\u4e3a\u524d\u9762\u6709k-1\u4e2a\u5143\u7d20\u6ca1\u6240\u4ee5\u53ef\u4ee5\u7ee7\u7eed\u5206\u4e3af&#91;k-1]=f&#91;k-2]+f&#91;k-3]\n                  \u5373\u5728f&#91;k-1]\u7684\u524d\u9762\u7ee7\u7eed\u67e5\u627ek--\n                  \u5373\u4e0b\u6b21\u5faa\u73af,mid=f&#91;k-1-1]-1\n                 *\/\n                index--;\n            } else if (key > temp&#91;mid]) {\/\/\u5411\u6570\u7ec4\u7684\u540e\u9762\u7684\u90e8\u5206\u8fdb\u884c\u67e5\u627e\n                low = mid + 1;\n                index -= 2;\n            } else {\/\/\u627e\u5230\u4e86\n                \/\/\u9700\u8981\u786e\u5b9a\u8fd4\u56de\u7684\u662f\u54ea\u4e2a\u4e0b\u6807\n                if (mid &lt;= high) {\n                    return mid;\n                } else {\n                    return high;\n                }\n            }\n        }\n        return -1;\n    }\n}<\/code><\/pre>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\">4.\u5206\u5757\u67e5\u627e<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5176\u5b9e\u5206\u5757\u67e5\u627e\u4e5f\u53ef\u4ee5\u7528\u4e8e\u65e0\u5e8f\u7684\u6570\u7ec4\u7684\uff0c\u4e0d\u8fc7\u6211\u6b63\u5728\u5199\u4ed6\u7684\u4ee3\u7801\uff0c\u5199\u5b8c\u4e86\u4f1a\u8865\u4e0a\u7684<\/code><\/pre>\n\n\n\n<p>\u5206\u5757\u67e5\u627e\uff08Block Search\uff09\u662f\u4e00\u79cd\u7ed3\u5408\u4e86<strong>\u987a\u5e8f\u67e5\u627e<\/strong>\u548c<strong>\u6298\u534a\u67e5\u627e<\/strong>\u7684\u6df7\u5408\u67e5\u627e\u7b97\u6cd5\uff0c\u7279\u522b\u9002\u5408\u7528\u4e8e<strong>\u5757\u5185\u65e0\u5e8f\u3001\u5757\u95f4\u6709\u5e8f<\/strong>\u7684\u6570\u636e\u7ed3\u6784\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u7b97\u6cd5\u539f\u7406<\/h4>\n\n\n\n<p>\u5206\u5757\u67e5\u627e\u5c06\u6570\u636e\u5206\u4e3a\u82e5\u5e72\u5757\uff08\u4e00\u822c\u5206\u4e3a\u6570\u636e\u7684\u603b\u4e2a\u6570\u5f00\u6839\u53f7\u4e2a\uff09\uff08\u611f\u89c9\u6700\u96be\u7684\u662f\u5206\u5757\uff09\uff0c\u6ee1\u8db3\uff1a<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>\u5757\u5185\u65e0\u5e8f<\/strong>\uff1a\u6bcf\u4e2a\u5757\u5185\u7684\u5143\u7d20\u53ef\u4ee5\u662f\u4efb\u610f\u987a\u5e8f<\/li>\n\n\n\n<li><strong>\u5757\u95f4\u6709\u5e8f<\/strong>\uff1a\u7b2ci\u5757\u7684\u6240\u6709\u5143\u7d20\u90fd\u5c0f\u4e8e\u7b2ci+1\u5757\u7684\u6240\u6709\u5143\u7d20<\/li>\n\n\n\n<li><strong>\u5efa\u7acb\u7d22\u5f15<\/strong>\uff1a\u4e3a\u6bcf\u4e2a\u5757\u5efa\u7acb\u7d22\u5f15\uff0c\u8bb0\u5f55\u5757\u7684\u6700\u5927\u503c\u548c\u8d77\u59cb\u4f4d\u7f6e<\/li>\n<\/ol>\n\n\n\n<p>\u5982\uff1a\u73b0\u6709\u6570\u7ec4{16, 5, 9, 12, 21, 18,32, 23, 37, 26, 45, 34,50, 48, 61, 52, 73, 66}\uff0c\u90a3\u4e48\u6839\u636e\u5206\u5757\u89c4\u5219\u53ef\u4ee5\u5206\u4e3a\u301016\uff0c5\uff0c9\uff0c12\u3011\u301021\uff0c18\uff0c32\uff0c23\u3011\u301037\uff0c26\uff0c45\uff0c34\u3011\u301050\uff0c48\uff0c61\uff0c52\u3011\u301073\uff0c66\u3011\u4f46\u662f\u53c8\u56e0\u4e3a\u524d\u4e00\u5757\u7684\u6700\u5927\u503c\u8981\u6bd4\u540e\u9762\u6240\u6709\u6570\u90fd\u8981\u5927\uff0c\u548c\u6700\u4f73\u5206\u5757\u6570\uff0c\u4fdd\u8bc1\u5757\u5185\u5143\u7d20\u5747\u5300\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5206\u4e3a\u301016, 5, 9, 12, 21, 18,\u3011\u301032, 23, 37, 26, 45, 34,\u3011\u301050, 48, 61, 52, 73, 66\u3011<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u7b97\u6cd5\u6b65\u9aa4<\/h4>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>\u5206\u5757<\/strong>\uff1a\u5c06\u6570\u7ec4\u5206\u6210m\u4e2a\u5757<\/li>\n\n\n\n<li><strong>\u5efa\u7acb\u7d22\u5f15\u8868<\/strong>\uff1a\u8bb0\u5f55\u6bcf\u4e2a\u5757\u7684\u6700\u5927\u503c\u548c\u8d77\u59cb\u5730\u5740<\/li>\n\n\n\n<li><strong>\u67e5\u627e<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u5148\u5728\u7d22\u5f15\u8868\u4e2d\u786e\u5b9a\u76ee\u6807\u6240\u5728\u7684\u5757\uff08\u6298\u534a\u67e5\u627e\u6216\u987a\u5e8f\u67e5\u627e\uff09<\/li>\n\n\n\n<li>\u7136\u540e\u5728\u786e\u5b9a\u7684\u5757\u5185\u8fdb\u884c\u987a\u5e8f\u67e5\u627e<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class BlockSearchDemo1 {\n    public static void main(String&#91;] args) {\n        \/\/ \u5206\u5757\u67e5\u627e\uff1a\u5757\u5185\u65e0\u5e8f\uff0c\u5757\u95f4\u6709\u5e8f\n        int&#91;] arr = { 16, 5, 9, 12, 21, 18,\n                32, 23, 37, 26, 45, 34,\n                50, 48, 61, 52, 73, 66 };\/\/\u5206\u5757\n\n        Block b1 = new Block(21, 0, 5);\/\/\u8c03\u7528\u5e95\u90e8Block\u7c7b\uff0c\u8bb0\u5f55\u6bcf\u4e00\u5757\u7684\u6700\u5927\u503c\uff0c\u8d77\u59cb\u7d22\u5f15\uff0c\u7ed3\u675f\u7d22\u5f15\n        Block b2 = new Block(45, 6, 11);\n        Block b3 = new Block(73, 12, 17);\n\n        Block&#91;] blockArr = { b1, b2, b3 };\/\/\u5728\u628a\u521b\u5efa\u7684block\u5bf9\u8c61\u653e\u8fdbblock\u6570\u7ec4\n\n        int num = 61;\/\/\u5b9a\u4e49\u76ee\u6807\u503c\n\n        int index = getIndex(blockArr, arr, num);\/\/\u628a\u5206\u5757\u540e\u6570\u7ec4\uff0c\u539f\u6570\u7ec4\uff0c\u76ee\u6807\u503c\u4ea4\u7531getIndex\u65b9\u6cd5\u64cd\u4f5c\n        System.out.println(\"num\u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15\u4e3a\uff1a\" + index);\n    }\n\n    private static int getIndex(Block&#91;] blockArr, int&#91;] arr, int num) {\n        int index = findIndexBlock(blockArr, num);\/\/\u4ea4\u7531findIndexBlock\u65b9\u6cd5\u67e5\u627e\u76ee\u6807\u503c\u5904\u4e8e\u54ea\u4e00\u533a\u5757\u4e2d\n        if (index == -1) {\n            return -1;\/\/\u76ee\u6807\u503c\u4e0d\u518d\u4efb\u4f55\u533a\u5757\n        }\n\n        int startIndex = blockArr&#91;index].getStartIndex();\/\/\u5f97\u5230\u76ee\u6807\u503c\u6240\u5728\u533a\u5757\u8d77\u59cb\u7d22\u5f15\n        int endIndex = blockArr&#91;index].getEndIndex();\/\/\u5f97\u5230\u76ee\u6807\u503c\u6240\u5728\u533a\u5757\u7ed3\u675f\u7d22\u5f15\n\n        for (int i = startIndex; i &lt;= endIndex; i++) {\n            if (arr&#91;i] == num) {\n                return i;\/\/\u5faa\u73af\u904d\u5386\u533a\u5757\u5339\u914d\u76ee\u6807\u503c\u5e76\u8fd4\u56de\u76ee\u6807\u503c\u7d22\u5f15\n            }\n        }\n        return -1;\/\/\u76ee\u6807\u503c\u4e0d\u518d\u76ee\u6807\u533a\u5757\u4e2d\uff0c\u76ee\u6807\u503c\u4e0d\u5728\u5f53\u524d\u6570\u7ec4\u4e2d\n\n    }\n\n    private static int findIndexBlock(Block&#91;] blockArr, int num) {\n        \/\/\u4ece0\u7d22\u5f15\u904d\u5386blockArr\uff0c\u5982\u679cnum\u5c0f\u4e8emax\uff0c\u90a3\u4e48num\u5c31\u5728\u8fd9\u4e00\u5757\u4e2d\n        for (int i = 0; i &lt; blockArr.length; i++) {\n            if (num &lt; blockArr&#91;i].getMax()) {\n                return i;\/\/\u8fd4\u56de\u6240\u5728\u533a\u5757\n            }\n        }\n        return -1;\/\/\u76ee\u6807\u503c\u4e0d\u5728\u4efb\u4f55\u533a\u5757\n    }\n\n    static class Block {\n        private int max;\n        private int startIndex;\n        private int endIndex;\n\n        public int getMax() {\n            return max;\n        }\n\n        public void setMax(int max) {\n            this.max = max;\n        }\n\n        public int getStartIndex() {\n            return startIndex;\n        }\n\n        public void setStartIndex(int startIndex) {\n            this.startIndex = startIndex;\n        }\n\n        public int getEndIndex() {\n            return endIndex;\n        }\n\n        public void setEndIndex(int endIndex) {\n            this.endIndex = endIndex;\n        }\n\n        public Block() {\n\n        }\n\n        public Block(int max, int startIndex, int endIndex) {\n            this.max = max;\n            this.startIndex = startIndex;\n            this.endIndex = endIndex;\n        }\n\n    }\n\n}\n<\/code><\/pre>\n<\/div><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">5.\u54c8\u5e0c\u67e5\u627e<\/h3>\n\n\n\n<p>\u54c8\u5e0c\u67e5\u627e\u662f\u5206\u5757\u67e5\u627e\u7684\u8fdb\u9636\u7248\uff0c\u9002\u7528\u4e8e\u6570\u636e\u4e00\u8fb9\u6dfb\u52a0\u4e00\u8fb9\u67e5\u627e\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<p>\u4e00\u822c\u662f\u6570\u7ec4 + \u94fe\u8868\u7684\u7ed3\u5408\u4f53\u6216\u8005\u662f\u6570\u7ec4+\u94fe\u8868 + \u7ea2\u9ed1\u6811\u7684\u7ed3\u5408\u4f53<\/p>\n\n\n\n<p>\u4f46\u662f\u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u4e00\u822c\u4e0d\u4f1a\u91c7\u53d6\u8fd9\u79cd\u65b9\u5f0f\uff0c\u56e0\u4e3a\u8fd9\u79cd\u65b9\u5f0f\u5bb9\u6613\u5bfc\u81f4\u4e00\u5757\u533a\u57df\u6dfb\u52a0\u7684\u5143\u7d20\u8fc7\u591a\uff0c\u5bfc\u81f4\u6548\u7387\u504f\u4f4e\u3002<\/p>\n\n\n\n<p>\u66f4\u591a\u7684\u662f\u5148\u8ba1\u7b97\u51fa\u5f53\u524d\u6570\u636e\u7684\u54c8\u5e0c\u503c\uff0c\u7528\u54c8\u5e0c\u503c\u8ddf\u6570\u7ec4\u7684\u957f\u5ea6\u8fdb\u884c\u8ba1\u7b97\uff0c\u8ba1\u7b97\u51fa\u5e94\u5b58\u5165\u7684\u4f4d\u7f6e\uff0c\u518d\u6302\u5728\u6570\u7ec4\u7684\u540e\u9762\u5f62\u6210\u94fe\u8868\uff0c\u5982\u679c\u6302\u7684\u5143\u7d20\u592a\u591a\u800c\u4e14\u6570\u7ec4\u957f\u5ea6\u8fc7\u957f\uff0c\u6211\u4eec\u4e5f\u4f1a\u628a\u94fe\u8868\u8f6c\u5316\u4e3a\u7ea2\u9ed1\u6811\uff0c\u8fdb\u4e00\u6b65\u63d0\u9ad8\u6548\u7387\u3002\uff08\u4e0d\u8fc7\u6211\u8fd8\u6ca1\u5b66\u5230\uff0c\u5c31\u4e0d\u597d\u4ecb\u7ecd\u4e86\uff09<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.\u6811\u8868\u67e5\u627e<\/h3>\n\n\n\n<p>\u57fa\u672c\u601d\u60f3\uff1a\u4e8c\u53c9\u67e5\u627e\u6811\u662f\u5148\u5bf9\u5f85\u67e5\u627e\u7684\u6570\u636e\u8fdb\u884c\u751f\u6210\u6811\uff0c\u786e\u4fdd\u6811\u7684\u5de6\u5206\u652f\u7684\u503c\u5c0f\u4e8e\u53f3\u5206\u652f\u7684\u503c\uff0c\u7136\u540e\u5728\u5c31\u884c\u548c\u6bcf\u4e2a\u8282\u70b9\u7684\u7236\u8282\u70b9\u6bd4\u8f83\u5927\u5c0f\uff0c\u67e5\u627e\u6700\u9002\u5408\u7684\u8303\u56f4\u3002 \u8fd9\u4e2a\u7b97\u6cd5\u7684\u67e5\u627e\u6548\u7387\u5f88\u9ad8\uff0c\u4f46\u662f\u5982\u679c\u4f7f\u7528\u8fd9\u79cd\u67e5\u627e\u65b9\u6cd5\u8981\u9996\u5148\u521b\u5efa\u6811\u3002<\/p>\n\n\n\n<p>\u3000\u3000\u4e8c\u53c9\u67e5\u627e\u6811\uff08BinarySearch Tree\uff0c\u4e5f\u53eb\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u6216\u79f0\u4e8c\u53c9\u6392\u5e8f\u6811Binary Sort Tree\uff09\uff0c\u5177\u6709\u4e0b\u5217\u6027\u8d28\u7684\u4e8c\u53c9\u6811\uff1a<\/p>\n\n\n\n<p>\u3000\u30001\uff09\u82e5\u4efb\u610f\u8282\u70b9\u5de6\u5b50\u6811\u4e0a\u6240\u6709\u7684\u6570\u636e\uff0c\u5747\u5c0f\u4e8e\u672c\u8eab\uff1b<\/p>\n\n\n\n<p>\u3000\u30002\uff09\u82e5\u4efb\u610f\u8282\u70b9\u53f3\u5b50\u6811\u4e0a\u6240\u6709\u7684\u6570\u636e\uff0c\u5747\u5927\u4e8e\u672c\u8eab\uff1b<\/p>\n\n\n\n<p>\u3000\u3000\u4e8c\u53c9\u67e5\u627e\u6811\u6027\u8d28\uff1a\u5bf9\u4e8c\u53c9\u67e5\u627e\u6811\u8fdb\u884c\u4e2d\u5e8f\u904d\u5386\uff0c\u5373\u53ef\u5f97\u5230\u6709\u5e8f\u7684\u6570\u5217\u3002\uff08\u4e0d\u8fc7\u6211\u4e5f\u6ca1\u5b66\uff0c\u4e5f\u4e0d\u597d\u4ecb\u7ecd\uff09<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u7efc\u4e0a\uff0c\u4e3a\u67e5\u627e\u7684\u51e0\u4e2a\u4e3b\u6d41\u7684\u7b97\u6cd5\uff0c\u611f\u8c22\u9605\u8bfb\uff01<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00.\u67e5\u627e 1.\u57fa\u672c\u67e5\u627e \u4ece0\u7d22\u5f15\u5f00\u59cb\u6328\u4e2a\u5f80\u540e\u67e5\u627e 2.\u4e8c\u5206\u67e5\u627e\/\u6298\u534a\u67e5\u627e \u524d\u63d0\u6761\u4ef6\uff1a\u6570\u7ec4\u4e2d\u7684\u6570\u636e\u5fc5\u987b\u662f\u6709\u5e8f\u7684\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,2],"tags":[],"class_list":["post-134","post","type-post","status-publish","format-standard","hentry","category-java","category-2"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=\/wp\/v2\/posts\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=134"}],"version-history":[{"count":0,"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=\/wp\/v2\/posts\/134\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}