{"id":57,"date":"2021-01-10T13:14:09","date_gmt":"2021-01-10T05:14:09","guid":{"rendered":"https:\/\/fireinsect.top\/?p=57"},"modified":"2021-02-04T18:59:22","modified_gmt":"2021-02-04T10:59:22","slug":"%e4%ba%8c%e5%88%86%e6%b3%95%e5%9c%a8%e6%9c%89%e5%ba%8f%e6%95%b0%e7%bb%84%e4%b8%ad%e6%9f%a5%e6%89%be%e6%9f%90%e4%b8%80%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fireinsect.top\/index.php\/2021\/01\/10\/%e4%ba%8c%e5%88%86%e6%b3%95%e5%9c%a8%e6%9c%89%e5%ba%8f%e6%95%b0%e7%bb%84%e4%b8%ad%e6%9f%a5%e6%89%be%e6%9f%90%e4%b8%80%e5%80%bc\/","title":{"rendered":"\u4e8c\u5206\u6cd5\u5728\u6709\u5e8f\u6570\u7ec4\u4e2d\u67e5\u627e\u67d0\u4e00\u503c"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code lang=\"java\" class=\"language-java line-numbers\">public class Find {\n\n  public static int find(int[] array, int aim) {\n    int left=0;\n    int right=array.length-1;\n    while(left&lt;=right){\n      int middle=(left+right)\/2;\n      int middlevalue=array[middle];\n      if(middlevalue==aim){\n        return middle;\n      }else if(middlevalue&lt;aim){\n        right=middle-1;\n      }else if(middlevalue&gt;aim){\n        left=middle+1;\n      }\n    }\n    return -1;\n  }\n  public static void main(String[] args) {\n    int[] array = {100, 90, 80, 75, 22, 3, 2};\n    int result1 = find(array, 22);\n    if (result1 == -1) {\n      System.out.println(\"22 \u4e0d\u5b58\u5728\u6570\u7ec4\u4e2d\");\n    } else {\n      System.out.println(\"22 \u5b58\u5728\u6570\u7ec4\u4e2d\uff0c\u7d22\u5f15\u503c\u662f \" + result1);\n    }\n\n    int result2 = find(array, 50);\n    if (result2 == -1) {\n      System.out.println(\"50 \u4e0d\u5b58\u5728\u6570\u7ec4\u4e2d\");\n    } else {\n      System.out.println(\"50 \u5b58\u5728\u6570\u7ec4\u4e2d\uff0c\u7d22\u5f15\u503c\u662f \" + result2);\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u5206\u6790\uff1a<\/p>\n\n\n\n<p>\u4e3b\u51fd\u6570\u4e3a\u8f93\u51fa\uff08\u4e0d\u8bba\uff09<\/p>\n\n\n\n<p>\u5728\u5b50\u51fd\u6570\u4e2d\uff0c\u8bbe\u5b9aleft,right\u4f5c\u4e3a\u6570\u7ec4\u4e24\u7aef\u503c\uff08right\u4e3a\u957f\u5ea6\u51cf\u4e00\uff09<\/p>\n\n\n\n<p>\u5f53left&gt;right\u65f6\u5019\u8df3\u51fa\u5faa\u73af<\/p>\n\n\n\n<p>\u8bbe\u5b9a\u4e00\u4e2amiddle\u4e3aright\u548cleft\u7684\u4e2d\u503c\uff0c\u63d0\u53d6middle\u4ee3\u8868\u7684\u6570\u7ec4\u4e2d\u7684\u6570<\/p>\n\n\n\n<p>\u5982\u679c\u63d0\u53d6\u6570\u4e3a\u76ee\u6807\u503c\u5219\u8f93\u51fa<\/p>\n\n\n\n<p>\u5982\u679c\u63d0\u53d6\u6570\u5927\u4e8e\u76ee\u6807\u503c\uff08\u5728\u5355\u8c03\u589e\u6570\u7ec4\u4e2d\uff09\u5219\u76ee\u6807\u503c\u5728\u63d0\u53d6\u6570\u524d\uff0c\u5219right=middle-1\uff1b<\/p>\n\n\n\n<p>\u53cd\u4e4b left=middle+1\uff1b<\/p>\n\n\n\n<p>\u4ee5\u6b64\u5bfb\u627e\u503c<\/p>\n\n\n\n<p>\u6ce8\uff1a\u6b64\u65b9\u6cd5\u4e5f\u53ef\u7528\u4e8e\u67e5\u627estring<\/p>\n\n\n\n<p>\u5229\u7528 string1.compareTo(string2)\u53ef\u4ee5\u5224\u65adstring\u7684\u5927\u5c0f\u5173\u7cfb\uff08\u5177\u4f53\u662f\u4ecestring\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u5f00\u59cb\u4f9d\u6b21\u6309ABCD\u6392\u5e8f\uff09\u5982\u679c\u8fd4\u56de\u503c\u662f\u8d1f\u6570\u5219string1\u5728string2\u524d\uff0c\u53cd\u4e4b\u5728\u540e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5206\u6790\uff1a \u4e3b\u51fd\u6570\u4e3a\u8f93\u51fa\uff08\u4e0d\u8bba\uff09 \u5728\u5b50\u51fd\u6570\u4e2d\uff0c\u8bbe\u5b9aleft,right\u4f5c\u4e3a\u6570\u7ec4\u4e24\u7aef\u503c\uff08right\u4e3a\u957f\u5ea6\u51cf\u4e00\uff09 \u5f53l [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[1,7],"tags":[],"class_list":["post-57","post","type-post","status-publish","format-standard","hentry","category-wcd","category-7"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/57"}],"collection":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/comments?post=57"}],"version-history":[{"count":2,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/57\/revisions"}],"predecessor-version":[{"id":94,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/57\/revisions\/94"}],"wp:attachment":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/media?parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/categories?post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/tags?post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}