代码语言:javascript复制
# encoding: utf-8
"""
Create on: 2018-08-24 上午1:32
author: sato
mail: ysudqfs@163.com
life is short, you need python
"""
# def insert_sort(array):
# # 从第二个开始循环
# for i in range(1, len(array)):
# # 认为他是最小的
# min = array[i]
# j = i - 1
# while j >= 0 and array[j] > min:
# array[j 1] = array[j]
# print(array)
#
# j -= 1
# array[j 1] = min
# print(array)
# return array
def bucketSort(nums):
# 选择一个最大的数
max_num = max(nums)
# 创建一个元素全是 0 的列表, 当做桶
bucket = [0] * (max_num 1)
# print(bucket)
# 把所有元素放入桶中, 即把对应元素个数加一
for i in nums:
bucket[i] = 1
# print(nums)
# print(bucket)
# 存储排序好的元素
sort_nums = []
# 取出桶中的元素
for j in range(len(bucket)):
if bucket[j] != 0:
for y in range(bucket[j]):
print(bucket[j])
sort_nums.append(j)
return sort_nums
# bucketSort(nums)
# if __name__ == "__main__":
# import random
#
# # array = [i for i in range(1, 11)]
# # random.shuffle(array)
# array = [1,5,6,8,4]
# print("排序前:", array)
# # new_array = insert_sort(array)
# new_array = bucketSort(array)
# print("排序后:", new_array)
def toStr(n, base):
convertString = "0123456789" "".join([chr(i) for i in range(65, 91)]) "".join([chr(i) for i in range(97, 123)])
if n < base:
return convertString[n]
else:
return toStr(n // base, base) convertString[n % base]
# print(toStr(600, 62))
def jumpFloor(number):
# write code here
tempArray = [1, 2]
if number >= 3:
for i in range(3, number 1):
tempArray[(i 1) % 2] = tempArray[0] tempArray[1]
return tempArray[(number 1) % 2]
print(jumpFloor(20))
# fibonacci
(((1 根号5 )/2)^n - ((1 - 根号5)/2)^n)/根号5