
算法初级
llx1026
愿在人工智能界找到自己的一席之地。。。
展开
-
使用python实现二分查找
import mathdef binary_search(list0, item):#list是已知的数组,item是要在list中寻找的数 low = 0 high = len(list0) - 1 while low <= high: mid = math.floor((low + high) / 2)#Python2中有自动向下取整功能,pytho原创 2017-09-18 19:28:08 · 660 阅读 · 0 评论 -
用python实现将数组元素按从小到大的顺序排列
def findSmallest(arr): smallest = arr[0]#将第一个元素的值作为最小值赋给smallest smallest_index = 0#将第一个值的索引作为最小值的索引赋给smallest_index for i in range(1, len(arr)): if arr[i] < smallest:#对列表arr中的元素进行原创 2017-09-18 21:37:03 · 18677 阅读 · 0 评论