{"id":87,"date":"2019-05-15T21:21:05","date_gmt":"2019-05-15T13:21:05","guid":{"rendered":"https:\/\/kanghaov.com\/?p=87"},"modified":"2020-07-22T19:16:51","modified_gmt":"2020-07-22T11:16:51","slug":"%e9%80%89%e6%8b%a9%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/nemo.cool\/87.html","title":{"rendered":"\u9009\u62e9\u6392\u5e8f"},"content":{"rendered":"<h1>\u672c\u7ae0\u5185\u5bb9<\/h1>\n<ul>\n<li>\u5b66\u4e60\u4e24\u79cd\u6700\u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\uff1a\u6570\u7ec4\u3001\u94fe\u8868<\/li>\n<li>\u5b66\u4e60\u7b2c\u4e00\u79cd\u6392\u5e8f\u7b97\u6cd5\uff1a\u9009\u62e9\u6392\u5e8f<\/li>\n<\/ul>\n<hr \/>\n<h3>\u6570\u7ec4\u548c\u94fe\u8868<\/h3>\n<ul>\n<li>\u9700\u8981\u5b58\u50a8\u591a\u9879\u6570\u636e\u65f6\uff0c\u6709\u4e24\u79cd\u57fa\u672c\u65b9\u5f0f\u2014\u2014\u6570\u7ec4\u548c\u94fe\u8868\u3002<\/li>\n<li>\u5728\u6570\u7ec4\u4e2d\u6240\u6709\u7684\u6570\u636e\u5728\u5185\u5b58\u4e2d\u90fd\u662f\u76f8\u8fde\u7684\uff0c\u5982\u8981\u6dfb\u52a0\u65b0\u5143\u7d20\u65f6\uff0c\u539f\u672c\u6570\u636e\u540e\u6ca1\u6709\u7a7a\u4f59\u7a7a\u95f4\u65f6\uff0c\u8ba1\u7b97\u673a\u5c31\u4f1a\u8fc1\u79fb\u8fd9\u4e9b\u6570\u636e\u5230\u5408\u9002\u7684\u5185\u5b58\u7a7a\u95f4\u3002\n<ul>\n<li>\u989d\u5916\u8bf7\u6c42\u7684\u4f4d\u7f6e\u53ef\u80fd\u6839\u672c\u7528\u4e0d\u4e0a\uff0c\u8fd9\u5c06\u6d6a\u8d39\u5185\u5b58\uff0c\u5373\u4f7f\u6ca1\u6709\u4f7f\u7528\uff0c\u5176\u4ed6\u6570\u636e\u4e5f\u5229\u7528\u4e0d\u4e86\u3002<\/li>\n<li>\u6570\u636e\u5b58\u50a8\u8d85\u8fc7\u9884\u5148\u5206\u914d\u7684\u7a7a\u95f4\u540e\u4f1a\u88ab\u6574\u4f53\u8fc1\u79fb\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u94fe\u8868<\/h4>\n<ul>\n<li>\u94fe\u8868\u4e2d\u7684\u5143\u7d20\u53ef\u80fd\u4f1a\u88ab\u5b58\u50a8\u5728\u4efb\u4f55\u5730\u65b9\u3002<\/li>\n<li>\u94fe\u8868\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u5b58\u50a8\u4e86\u4e0b\u4e00\u4e2a\u5143\u7d20\u7684\u5730\u5740\uff0c\u4ece\u800c\u4f7f\u4e00\u7cfb\u5217\u968f\u673a\u7684\u5185\u5b58\u5730\u5740\u4e32\u5728\u4e00\u8d77\u3002<\/li>\n<li>\u5728\u94fe\u8868\u4e2d\u6dfb\u52a0\u5143\u7d20\u5f88\u5bb9\u6613\uff1a\u53ea\u9700\u8981\u5c06\u5176\u653e\u5165\u5185\u5b58\uff0c\u5e76\u5c06\u5176\u5730\u5740\u5b58\u50a8\u5230\u524d\u4e00\u4e2a\u5143\u7d20\u4e2d\u3002<\/li>\n<li>\u94fe\u8868\u652f\u6301\u987a\u5e8f\u8bbf\u95ee\u3002<\/li>\n<\/ul>\n<h4>\u6570\u7ec4<\/h4>\n<ul>\n<li>\u94fe\u8868\u4e2d\u5b58\u5728\u7740\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u5728\u9700\u8981\u8bfb\u53d6\u94fe\u8868\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u65f6\uff0c\u5e76\u4e0d\u80fd\u76f4\u63a5\u8bfb\u53d6\uff0c\u56e0\u4e3a\u4e0d\u77e5\u9053\u5b83\u6240\u5904\u7684\u5730\u5740\uff0c\u5fc5\u987b\u5148\u8bbf\u95ee\u5143\u7d20#1\uff0c\u4ece\u4e2d\u83b7\u53d6\u5143\u7d20#2\u7684\u5730\u5740\uff0c\u518d\u8bbf\u95ee\u5143\u7d20#2\u5e76\u4ece\u4e2d\u83b7\u53d6\u5143\u7d20#3\u7684\u5730\u5740\uff0c&#8230;\uff0c\u76f4\u5230\u8bbf\u95ee\u5230\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u9700\u8981\u8df3\u8dc3\u8bbf\u95ee\uff0c\u94fe\u8868\u7684\u6548\u7387\u771f\u7684\u5f88\u4f4e\u3002<\/li>\n<li>\u6570\u7ec4\u4e0d\u4e00\u6837\uff0c\u6211\u4eec\u77e5\u9053\u6bcf\u4e2a\u5143\u7d20\u7684<del>\u5730\u5740<\/del>\u7d22\u5f15\u3002<\/li>\n<li>\u6570\u7ec4\u652f\u6301\u968f\u673a\u8bbf\u95ee\u3002<\/li>\n<\/ul>\n<h4>\u5e38\u89c1\u7684\u6570\u7ec4\u548c\u94fe\u8868\u64cd\u4f5c\u7684\u8fd0\u884c\u65f6\u95f4\uff1a<\/h4>\n<p>\u6570\u7ec4  \u94fe\u8868<br \/>\n\u8bfb\u53d6  O(1)    O(n)<br \/>\n\u63d2\u5165  O(n)    O(1)<br \/>\n\u5220\u9664  O(n)<br \/>\nO(1)<\/p>\n<p>O(n)=\u7ebf\u6027\u65f6\u95f4<\/p>\n<h2>O(1)=\u5e38\u91cf\u65f6\u95f4<\/h2>\n<h3>\u9009\u62e9\u6392\u5e8f<\/h3>\n<ul>\n<li>\u8fd0\u884c\u65f6\u95f4\uff1aO(n^2)<\/li>\n<\/ul>\n<h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<ol>\n<li>\u627e\u51fa\u6570\u7ec4\u4e2d\u6700\u5c0f\u5143\u7d20\uff1a<\/li>\n<\/ol>\n<pre><code class=\"language-python \">def findSmallest(arr):\n    smallest = arr[0]\n    smallest_index = 0\n    for i in range(1, len(arr)):\n        if arr[i] &lt; smallest:\n            smallest = arr[i]\n            smallest_index = i\n    return smallest_index\n\n<\/code><\/pre>\n<p>2.\u7f16\u5199\u6392\u5e8f\u7b97\u6cd5<\/p>\n<pre><code class=\"language-python \">def selectionSort(arr):\n    newArry = []\n    for i in range(len(arr)):\n        smallest = findSmallest(arr)\n        newArry.append(arr.pop(smallest)) #arr\u5254\u9664\u4e00\u4e2a\u503c\uff0cnewArry\u6dfb\u52a0\u4e00\u4e2a\n    return newArry\n<\/code><\/pre>\n<ol start=\"3\">\n<li>\u5b8c\u6574\u8fd0\u884c\uff1a<\/li>\n<\/ol>\n<pre><code class=\"language-python \">def findSmallest(arr):\n    smallest = arr[0]\n    smallest_index = 0\n    for i in range(1, len(arr)):\n        if arr[i] &lt; smallest:\n            smallest = arr[i]\n            smallest_index = i\n    return smallest_index\n\n\ndef selectionSort(arr):\n    newArry = []\n    for i in range(len(arr)):\n        smallest = findSmallest(arr)\n        newArry.append(arr.pop(smallest))\n    return newArry\n\n\nprint(selectionSort([5, 3, 6, 9, 9, 6, 9]))\n\n<\/code><\/pre>\n<h3>\u5c0f\u7ed3<\/h3>\n<ul>\n<li>\u8ba1\u7b97\u673a\u5185\u5b58\u72b9\u5982\u4e00\u5927\u5806\u62bd\u5c49<\/li>\n<li>\u9700\u8981\u5b58\u50a8\u591a\u4e2a\u5143\u7d20\u65f6\uff0c\u53ef\u4f7f\u7528\u6570\u7ec4\u6216\u94fe\u8868<\/li>\n<li>\u6570\u7ec4\u7684\u5143\u7d20\u90fd\u5728\u4e00\u8d77<\/li>\n<li>\u94fe\u8868\u7684\u5143\u7d20\u662f\u5206\u5f00\u7684\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u5b58\u50a8\u4e86\u4e0b\u4e00\u4e2a\u5143\u7d20\u7684\u5730\u5740<\/li>\n<li>\u6570\u7ec4\u7684\u8bfb\u53d6\u901f\u5ea6\u5f88\u5feb<\/li>\n<li>\u94fe\u8868\u7684\u63d2\u5165\u548c\u5220\u9664\u901f\u5ea6\u5f88\u5feb<\/li>\n<li>\u5728\u540c\u4e00\u4e2a\u6570\u7ec4\u4e2d\uff0c\u6240\u6709\u5143\u7d20\u7684\u7c7b\u578b\u90fd\u5fc5\u987b\u76f8\u540c(\u90fd\u4e3aint,double\u7b49)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7ae0\u5185\u5bb9 \u5b66\u4e60\u4e24\u79cd\u6700\u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\uff1a\u6570\u7ec4\u3001\u94fe\u8868 \u5b66\u4e60\u7b2c\u4e00\u79cd\u6392\u5e8f\u7b97\u6cd5\uff1a\u9009\u62e9\u6392\u5e8f \u6570\u7ec4\u548c\u94fe\u8868 \u9700\u8981\u5b58\u50a8\u591a\u9879\u6570\u636e\u65f6\uff0c\u6709\u4e24\u79cd\u57fa\u672c\u65b9\u5f0f\u2014\u2014\u6570\u7ec4\u548c\u94fe\u8868\u3002 \u5728\u6570\u7ec4\u4e2d\u6240\u6709\u7684\u6570\u636e\u5728\u5185\u5b58\u4e2d\u90fd\u662f\u76f8\u8fde\u7684\uff0c\u5982\u8981\u6dfb\u52a0\u65b0\u5143\u7d20\u65f6\uff0c\u539f\u672c\u6570\u636e\u540e\u6ca1\u6709\u7a7a\u4f59\u7a7a\u95f4\u65f6\uff0c\u8ba1\u7b97\u673a\u5c31\u4f1a\u8fc1\u79fb\u8fd9\u4e9b\u6570\u636e\u5230\u5408\u9002\u7684\u5185\u5b58\u7a7a\u95f4\u3002 \u989d\u5916\u8bf7\u6c42\u7684\u4f4d\u7f6e\u53ef\u80fd\u6839\u672c\u7528\u4e0d\u4e0a\uff0c\u8fd9\u5c06\u6d6a\u8d39\u5185\u5b58\uff0c\u5373\u4f7f\u6ca1\u6709\u4f7f\u7528\uff0c\u5176\u4ed6\u6570\u636e\u4e5f\u5229\u7528\u4e0d\u4e86\u3002 \u6570\u636e\u5b58\u50a8\u8d85\u8fc7\u9884\u5148\u5206\u914d\u7684\u7a7a\u95f4\u540e\u4f1a\u88ab\u6574\u4f53\u8fc1\u79fb\u3002 \u94fe\u8868 \u94fe\u8868\u4e2d\u7684\u5143\u7d20\u53ef\u80fd\u4f1a\u88ab\u5b58\u50a8\u5728\u4efb\u4f55\u5730\u65b9\u3002 \u94fe\u8868\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u5b58\u50a8\u4e86\u4e0b\u4e00\u4e2a\u5143\u7d20\u7684\u5730\u5740\uff0c\u4ece\u800c\u4f7f\u4e00\u7cfb\u5217\u968f\u673a\u7684\u5185\u5b58\u5730\u5740\u4e32\u5728\u4e00\u8d77\u3002 \u5728\u94fe\u8868\u4e2d\u6dfb\u52a0\u5143\u7d20\u5f88\u5bb9\u6613\uff1a\u53ea\u9700\u8981\u5c06\u5176\u653e\u5165\u5185\u5b58\uff0c\u5e76\u5c06\u5176\u5730\u5740\u5b58\u50a8\u5230\u524d\u4e00\u4e2a\u5143\u7d20\u4e2d\u3002 \u94fe\u8868\u652f\u6301\u987a\u5e8f\u8bbf\u95ee\u3002 \u6570\u7ec4 \u94fe\u8868\u4e2d\u5b58\u5728\u7740\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u5728\u9700\u8981\u8bfb\u53d6\u94fe\u8868\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u65f6\uff0c\u5e76\u4e0d\u80fd\u76f4\u63a5\u8bfb\u53d6\uff0c\u56e0\u4e3a\u4e0d\u77e5\u9053\u5b83\u6240\u5904\u7684\u5730\u5740\uff0c\u5fc5\u987b\u5148\u8bbf\u95ee\u5143\u7d20#1\uff0c\u4ece\u4e2d\u83b7\u53d6\u5143\u7d20#2\u7684\u5730\u5740\uff0c\u518d\u8bbf\u95ee\u5143\u7d20#2\u5e76\u4ece\u4e2d\u83b7\u53d6\u5143\u7d20#3\u7684\u5730\u5740\uff0c&#8230;\uff0c\u76f4\u5230\u8bbf\u95ee\u5230\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u9700\u8981\u8df3\u8dc3\u8bbf\u95ee\uff0c\u94fe\u8868\u7684\u6548\u7387\u771f\u7684\u5f88\u4f4e\u3002 \u6570\u7ec4\u4e0d\u4e00\u6837\uff0c\u6211\u4eec\u77e5\u9053\u6bcf\u4e2a\u5143\u7d20\u7684\u5730\u5740\u7d22\u5f15\u3002 \u6570\u7ec4\u652f\u6301\u968f\u673a\u8bbf\u95ee\u3002 \u5e38\u89c1\u7684\u6570\u7ec4\u548c\u94fe\u8868\u64cd\u4f5c\u7684\u8fd0\u884c\u65f6\u95f4\uff1a \u6570\u7ec4 \u94fe\u8868 \u8bfb\u53d6 O(1) O(n) \u63d2\u5165 O(n) O(1) \u5220\u9664 O(n) O(1) O(n)=\u7ebf\u6027\u65f6\u95f4 O(1)=\u5e38\u91cf\u65f6\u95f4 \u9009\u62e9\u6392\u5e8f \u8fd0\u884c\u65f6\u95f4\uff1aO(n^2) \u793a\u4f8b\u4ee3\u7801\uff1a \u627e\u51fa\u6570\u7ec4\u4e2d\u6700\u5c0f\u5143\u7d20\uff1a def findSmallest(arr): smallest = arr[0] smallest_index = 0 for i in range(1, len(arr)): if arr[i] &lt; smallest: smallest = arr[i] [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":75,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,28],"tags":[10,23,29],"class_list":["post-87","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-algorithm","category-basic-concepts","tag-python","tag-23","tag-29"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u9009\u62e9\u6392\u5e8f - Nemo<\/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:\/\/nemo.cool\/87.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u9009\u62e9\u6392\u5e8f - Nemo\" \/>\n<meta property=\"og:description\" content=\"\u672c\u7ae0\u5185\u5bb9 \u5b66\u4e60\u4e24\u79cd\u6700\u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\uff1a\u6570\u7ec4\u3001\u94fe\u8868 \u5b66\u4e60\u7b2c\u4e00\u79cd\u6392\u5e8f\u7b97\u6cd5\uff1a\u9009\u62e9\u6392\u5e8f \u6570\u7ec4\u548c\u94fe\u8868 \u9700\u8981\u5b58\u50a8\u591a\u9879\u6570\u636e\u65f6\uff0c\u6709\u4e24\u79cd\u57fa\u672c\u65b9\u5f0f\u2014\u2014\u6570\u7ec4\u548c\u94fe\u8868\u3002 \u5728\u6570\u7ec4\u4e2d\u6240\u6709\u7684\u6570\u636e\u5728\u5185\u5b58\u4e2d\u90fd\u662f\u76f8\u8fde\u7684\uff0c\u5982\u8981\u6dfb\u52a0\u65b0\u5143\u7d20\u65f6\uff0c\u539f\u672c\u6570\u636e\u540e\u6ca1\u6709\u7a7a\u4f59\u7a7a\u95f4\u65f6\uff0c\u8ba1\u7b97\u673a\u5c31\u4f1a\u8fc1\u79fb\u8fd9\u4e9b\u6570\u636e\u5230\u5408\u9002\u7684\u5185\u5b58\u7a7a\u95f4\u3002 \u989d\u5916\u8bf7\u6c42\u7684\u4f4d\u7f6e\u53ef\u80fd\u6839\u672c\u7528\u4e0d\u4e0a\uff0c\u8fd9\u5c06\u6d6a\u8d39\u5185\u5b58\uff0c\u5373\u4f7f\u6ca1\u6709\u4f7f\u7528\uff0c\u5176\u4ed6\u6570\u636e\u4e5f\u5229\u7528\u4e0d\u4e86\u3002 \u6570\u636e\u5b58\u50a8\u8d85\u8fc7\u9884\u5148\u5206\u914d\u7684\u7a7a\u95f4\u540e\u4f1a\u88ab\u6574\u4f53\u8fc1\u79fb\u3002 \u94fe\u8868 \u94fe\u8868\u4e2d\u7684\u5143\u7d20\u53ef\u80fd\u4f1a\u88ab\u5b58\u50a8\u5728\u4efb\u4f55\u5730\u65b9\u3002 \u94fe\u8868\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u5b58\u50a8\u4e86\u4e0b\u4e00\u4e2a\u5143\u7d20\u7684\u5730\u5740\uff0c\u4ece\u800c\u4f7f\u4e00\u7cfb\u5217\u968f\u673a\u7684\u5185\u5b58\u5730\u5740\u4e32\u5728\u4e00\u8d77\u3002 \u5728\u94fe\u8868\u4e2d\u6dfb\u52a0\u5143\u7d20\u5f88\u5bb9\u6613\uff1a\u53ea\u9700\u8981\u5c06\u5176\u653e\u5165\u5185\u5b58\uff0c\u5e76\u5c06\u5176\u5730\u5740\u5b58\u50a8\u5230\u524d\u4e00\u4e2a\u5143\u7d20\u4e2d\u3002 \u94fe\u8868\u652f\u6301\u987a\u5e8f\u8bbf\u95ee\u3002 \u6570\u7ec4 \u94fe\u8868\u4e2d\u5b58\u5728\u7740\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u5728\u9700\u8981\u8bfb\u53d6\u94fe\u8868\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u65f6\uff0c\u5e76\u4e0d\u80fd\u76f4\u63a5\u8bfb\u53d6\uff0c\u56e0\u4e3a\u4e0d\u77e5\u9053\u5b83\u6240\u5904\u7684\u5730\u5740\uff0c\u5fc5\u987b\u5148\u8bbf\u95ee\u5143\u7d20#1\uff0c\u4ece\u4e2d\u83b7\u53d6\u5143\u7d20#2\u7684\u5730\u5740\uff0c\u518d\u8bbf\u95ee\u5143\u7d20#2\u5e76\u4ece\u4e2d\u83b7\u53d6\u5143\u7d20#3\u7684\u5730\u5740\uff0c&#8230;\uff0c\u76f4\u5230\u8bbf\u95ee\u5230\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u9700\u8981\u8df3\u8dc3\u8bbf\u95ee\uff0c\u94fe\u8868\u7684\u6548\u7387\u771f\u7684\u5f88\u4f4e\u3002 \u6570\u7ec4\u4e0d\u4e00\u6837\uff0c\u6211\u4eec\u77e5\u9053\u6bcf\u4e2a\u5143\u7d20\u7684\u5730\u5740\u7d22\u5f15\u3002 \u6570\u7ec4\u652f\u6301\u968f\u673a\u8bbf\u95ee\u3002 \u5e38\u89c1\u7684\u6570\u7ec4\u548c\u94fe\u8868\u64cd\u4f5c\u7684\u8fd0\u884c\u65f6\u95f4\uff1a \u6570\u7ec4 \u94fe\u8868 \u8bfb\u53d6 O(1) O(n) \u63d2\u5165 O(n) O(1) \u5220\u9664 O(n) O(1) O(n)=\u7ebf\u6027\u65f6\u95f4 O(1)=\u5e38\u91cf\u65f6\u95f4 \u9009\u62e9\u6392\u5e8f \u8fd0\u884c\u65f6\u95f4\uff1aO(n^2) \u793a\u4f8b\u4ee3\u7801\uff1a \u627e\u51fa\u6570\u7ec4\u4e2d\u6700\u5c0f\u5143\u7d20\uff1a def findSmallest(arr): smallest = arr[0] smallest_index = 0 for i in range(1, len(arr)): if arr[i] &lt; smallest: smallest = arr[i] [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nemo.cool\/87.html\" \/>\n<meta property=\"og:site_name\" content=\"Nemo\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-15T13:21:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-07-22T11:16:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/nemo.cool\/wp-content\/uploads\/2019\/05\/timg-2.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"680\" \/>\n\t<meta property=\"og:image:height\" content=\"453\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nemo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nemo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/87.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/87.html\"},\"author\":{\"name\":\"Nemo\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/#\\\/schema\\\/person\\\/698f803ee811e2b140a90f5d5de913d2\"},\"headline\":\"\u9009\u62e9\u6392\u5e8f\",\"datePublished\":\"2019-05-15T13:21:05+00:00\",\"dateModified\":\"2020-07-22T11:16:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/87.html\"},\"wordCount\":16,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/#\\\/schema\\\/person\\\/698f803ee811e2b140a90f5d5de913d2\"},\"image\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/87.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/timg-2.jpg\",\"keywords\":[\"python\",\"\u7b97\u6cd5\",\"\u7b97\u6cd5\u56fe\u89e3\"],\"articleSection\":[\"Algorithm Notes\",\"Basic Concepts\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nemo.cool\\\/87.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/87.html\",\"url\":\"https:\\\/\\\/nemo.cool\\\/87.html\",\"name\":\"\u9009\u62e9\u6392\u5e8f - Nemo\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/87.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/87.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/timg-2.jpg\",\"datePublished\":\"2019-05-15T13:21:05+00:00\",\"dateModified\":\"2020-07-22T11:16:51+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/87.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nemo.cool\\\/87.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/87.html#primaryimage\",\"url\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/timg-2.jpg\",\"contentUrl\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/timg-2.jpg\",\"width\":680,\"height\":453},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/87.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\\\/\\\/nemo.cool\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u9009\u62e9\u6392\u5e8f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/#website\",\"url\":\"https:\\\/\\\/nemo.cool\\\/\",\"name\":\"Nemo\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/#\\\/schema\\\/person\\\/698f803ee811e2b140a90f5d5de913d2\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nemo.cool\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/nemo.cool\\\/#\\\/schema\\\/person\\\/698f803ee811e2b140a90f5d5de913d2\",\"name\":\"Nemo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg\",\"url\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg\",\"caption\":\"Nemo\"},\"logo\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg\"},\"sameAs\":[\"https:\\\/\\\/nemo.cool\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u9009\u62e9\u6392\u5e8f - Nemo","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:\/\/nemo.cool\/87.html","og_locale":"en_US","og_type":"article","og_title":"\u9009\u62e9\u6392\u5e8f - Nemo","og_description":"\u672c\u7ae0\u5185\u5bb9 \u5b66\u4e60\u4e24\u79cd\u6700\u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\uff1a\u6570\u7ec4\u3001\u94fe\u8868 \u5b66\u4e60\u7b2c\u4e00\u79cd\u6392\u5e8f\u7b97\u6cd5\uff1a\u9009\u62e9\u6392\u5e8f \u6570\u7ec4\u548c\u94fe\u8868 \u9700\u8981\u5b58\u50a8\u591a\u9879\u6570\u636e\u65f6\uff0c\u6709\u4e24\u79cd\u57fa\u672c\u65b9\u5f0f\u2014\u2014\u6570\u7ec4\u548c\u94fe\u8868\u3002 \u5728\u6570\u7ec4\u4e2d\u6240\u6709\u7684\u6570\u636e\u5728\u5185\u5b58\u4e2d\u90fd\u662f\u76f8\u8fde\u7684\uff0c\u5982\u8981\u6dfb\u52a0\u65b0\u5143\u7d20\u65f6\uff0c\u539f\u672c\u6570\u636e\u540e\u6ca1\u6709\u7a7a\u4f59\u7a7a\u95f4\u65f6\uff0c\u8ba1\u7b97\u673a\u5c31\u4f1a\u8fc1\u79fb\u8fd9\u4e9b\u6570\u636e\u5230\u5408\u9002\u7684\u5185\u5b58\u7a7a\u95f4\u3002 \u989d\u5916\u8bf7\u6c42\u7684\u4f4d\u7f6e\u53ef\u80fd\u6839\u672c\u7528\u4e0d\u4e0a\uff0c\u8fd9\u5c06\u6d6a\u8d39\u5185\u5b58\uff0c\u5373\u4f7f\u6ca1\u6709\u4f7f\u7528\uff0c\u5176\u4ed6\u6570\u636e\u4e5f\u5229\u7528\u4e0d\u4e86\u3002 \u6570\u636e\u5b58\u50a8\u8d85\u8fc7\u9884\u5148\u5206\u914d\u7684\u7a7a\u95f4\u540e\u4f1a\u88ab\u6574\u4f53\u8fc1\u79fb\u3002 \u94fe\u8868 \u94fe\u8868\u4e2d\u7684\u5143\u7d20\u53ef\u80fd\u4f1a\u88ab\u5b58\u50a8\u5728\u4efb\u4f55\u5730\u65b9\u3002 \u94fe\u8868\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u5b58\u50a8\u4e86\u4e0b\u4e00\u4e2a\u5143\u7d20\u7684\u5730\u5740\uff0c\u4ece\u800c\u4f7f\u4e00\u7cfb\u5217\u968f\u673a\u7684\u5185\u5b58\u5730\u5740\u4e32\u5728\u4e00\u8d77\u3002 \u5728\u94fe\u8868\u4e2d\u6dfb\u52a0\u5143\u7d20\u5f88\u5bb9\u6613\uff1a\u53ea\u9700\u8981\u5c06\u5176\u653e\u5165\u5185\u5b58\uff0c\u5e76\u5c06\u5176\u5730\u5740\u5b58\u50a8\u5230\u524d\u4e00\u4e2a\u5143\u7d20\u4e2d\u3002 \u94fe\u8868\u652f\u6301\u987a\u5e8f\u8bbf\u95ee\u3002 \u6570\u7ec4 \u94fe\u8868\u4e2d\u5b58\u5728\u7740\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u5728\u9700\u8981\u8bfb\u53d6\u94fe\u8868\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u65f6\uff0c\u5e76\u4e0d\u80fd\u76f4\u63a5\u8bfb\u53d6\uff0c\u56e0\u4e3a\u4e0d\u77e5\u9053\u5b83\u6240\u5904\u7684\u5730\u5740\uff0c\u5fc5\u987b\u5148\u8bbf\u95ee\u5143\u7d20#1\uff0c\u4ece\u4e2d\u83b7\u53d6\u5143\u7d20#2\u7684\u5730\u5740\uff0c\u518d\u8bbf\u95ee\u5143\u7d20#2\u5e76\u4ece\u4e2d\u83b7\u53d6\u5143\u7d20#3\u7684\u5730\u5740\uff0c&#8230;\uff0c\u76f4\u5230\u8bbf\u95ee\u5230\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u9700\u8981\u8df3\u8dc3\u8bbf\u95ee\uff0c\u94fe\u8868\u7684\u6548\u7387\u771f\u7684\u5f88\u4f4e\u3002 \u6570\u7ec4\u4e0d\u4e00\u6837\uff0c\u6211\u4eec\u77e5\u9053\u6bcf\u4e2a\u5143\u7d20\u7684\u5730\u5740\u7d22\u5f15\u3002 \u6570\u7ec4\u652f\u6301\u968f\u673a\u8bbf\u95ee\u3002 \u5e38\u89c1\u7684\u6570\u7ec4\u548c\u94fe\u8868\u64cd\u4f5c\u7684\u8fd0\u884c\u65f6\u95f4\uff1a \u6570\u7ec4 \u94fe\u8868 \u8bfb\u53d6 O(1) O(n) \u63d2\u5165 O(n) O(1) \u5220\u9664 O(n) O(1) O(n)=\u7ebf\u6027\u65f6\u95f4 O(1)=\u5e38\u91cf\u65f6\u95f4 \u9009\u62e9\u6392\u5e8f \u8fd0\u884c\u65f6\u95f4\uff1aO(n^2) \u793a\u4f8b\u4ee3\u7801\uff1a \u627e\u51fa\u6570\u7ec4\u4e2d\u6700\u5c0f\u5143\u7d20\uff1a def findSmallest(arr): smallest = arr[0] smallest_index = 0 for i in range(1, len(arr)): if arr[i] &lt; smallest: smallest = arr[i] [&hellip;]","og_url":"https:\/\/nemo.cool\/87.html","og_site_name":"Nemo","article_published_time":"2019-05-15T13:21:05+00:00","article_modified_time":"2020-07-22T11:16:51+00:00","og_image":[{"width":680,"height":453,"url":"https:\/\/nemo.cool\/wp-content\/uploads\/2019\/05\/timg-2.jpg","type":"image\/jpeg"}],"author":"Nemo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nemo","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nemo.cool\/87.html#article","isPartOf":{"@id":"https:\/\/nemo.cool\/87.html"},"author":{"name":"Nemo","@id":"https:\/\/nemo.cool\/#\/schema\/person\/698f803ee811e2b140a90f5d5de913d2"},"headline":"\u9009\u62e9\u6392\u5e8f","datePublished":"2019-05-15T13:21:05+00:00","dateModified":"2020-07-22T11:16:51+00:00","mainEntityOfPage":{"@id":"https:\/\/nemo.cool\/87.html"},"wordCount":16,"commentCount":0,"publisher":{"@id":"https:\/\/nemo.cool\/#\/schema\/person\/698f803ee811e2b140a90f5d5de913d2"},"image":{"@id":"https:\/\/nemo.cool\/87.html#primaryimage"},"thumbnailUrl":"https:\/\/nemo.cool\/wp-content\/uploads\/2019\/05\/timg-2.jpg","keywords":["python","\u7b97\u6cd5","\u7b97\u6cd5\u56fe\u89e3"],"articleSection":["Algorithm Notes","Basic Concepts"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nemo.cool\/87.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nemo.cool\/87.html","url":"https:\/\/nemo.cool\/87.html","name":"\u9009\u62e9\u6392\u5e8f - Nemo","isPartOf":{"@id":"https:\/\/nemo.cool\/#website"},"primaryImageOfPage":{"@id":"https:\/\/nemo.cool\/87.html#primaryimage"},"image":{"@id":"https:\/\/nemo.cool\/87.html#primaryimage"},"thumbnailUrl":"https:\/\/nemo.cool\/wp-content\/uploads\/2019\/05\/timg-2.jpg","datePublished":"2019-05-15T13:21:05+00:00","dateModified":"2020-07-22T11:16:51+00:00","breadcrumb":{"@id":"https:\/\/nemo.cool\/87.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nemo.cool\/87.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/nemo.cool\/87.html#primaryimage","url":"https:\/\/nemo.cool\/wp-content\/uploads\/2019\/05\/timg-2.jpg","contentUrl":"https:\/\/nemo.cool\/wp-content\/uploads\/2019\/05\/timg-2.jpg","width":680,"height":453},{"@type":"BreadcrumbList","@id":"https:\/\/nemo.cool\/87.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/nemo.cool\/"},{"@type":"ListItem","position":2,"name":"\u9009\u62e9\u6392\u5e8f"}]},{"@type":"WebSite","@id":"https:\/\/nemo.cool\/#website","url":"https:\/\/nemo.cool\/","name":"Nemo","description":"","publisher":{"@id":"https:\/\/nemo.cool\/#\/schema\/person\/698f803ee811e2b140a90f5d5de913d2"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nemo.cool\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/nemo.cool\/#\/schema\/person\/698f803ee811e2b140a90f5d5de913d2","name":"Nemo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/nemo.cool\/wp-content\/uploads\/2024\/01\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg","url":"https:\/\/nemo.cool\/wp-content\/uploads\/2024\/01\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg","contentUrl":"https:\/\/nemo.cool\/wp-content\/uploads\/2024\/01\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg","caption":"Nemo"},"logo":{"@id":"https:\/\/nemo.cool\/wp-content\/uploads\/2024\/01\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg"},"sameAs":["https:\/\/nemo.cool"]}]}},"_links":{"self":[{"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/posts\/87","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/comments?post=87"}],"version-history":[{"count":0,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/posts\/87\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/media\/75"}],"wp:attachment":[{"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/media?parent=87"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/categories?post=87"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/tags?post=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}