![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法和数据结构
文章平均质量分 63
weixin_38892128
这个作者很懒,什么都没留下…
展开
-
算法:排列和组合
组合# n取k的组合数def combination(n:int,k:int) : res = [] def traceback(temp:list,index:int): if len(temp) == k: res.append(temp[:]) else: for i in range(index,n+1): temp.append(i)原创 2021-03-13 23:28:05 · 71 阅读 · 0 评论 -
滑动窗口
https://leetcode-cn.com/problems/minimum-window-substring/solution/hua-dong-chuang-kou-by-powcai-2/原创 2020-11-09 00:09:04 · 87 阅读 · 0 评论 -
python 微信红包算法
红包总额m,分给n个人,每人最少1分,随机分配import randomimport mathdef red_packet(res_money, res_num): res = [] while res_num > 1: min = 1 # 红包最小值1分钱 max = res_money/res_num*2 # 红包最大值限定平均...原创 2020-04-12 15:59:30 · 1717 阅读 · 0 评论 -
动态规划问题
三步问题。有个小孩正在上楼梯,楼梯有n阶台阶,小孩一次可以上1阶、2阶或3阶。实现一种方法,计算小孩有多少种上楼梯的方式。结果可能很大,你需要对结果模1000000007。示例1:输入:n = 3输出:4说明: 有四种走法示例2:输入:n = 5输出:13https://leetcode-cn.com/problems/three-steps-problem-lcci/comm...原创 2020-02-14 23:01:22 · 109 阅读 · 0 评论 -
二叉树的遍历 python
__author__ = 'hp'class BiTreeNode: def __init__(self, data): self.data = data self.lchild = None self.rchild = Nonea = BiTreeNode('A')b = BiTreeNode('B')c = BiTreeNod...原创 2020-02-03 17:49:56 · 128 阅读 · 0 评论 -
算法-排序-python
冒泡排序__author__ = 'hp'def bubble_sort(li): "冒泡排序" n = len(li) for i in range(n-1): for j in range(n-1-i): if li[j]>li[j+1]: li[j],li[j+1] = li[j+1]...原创 2020-02-02 17:59:12 · 165 阅读 · 0 评论 -
递归问题:斐波那契,汉诺塔
斐波那契函数__author__ = 'hp'import syssys.setrecursionlimit(10000)def fibo(n): if n == 0: return 0 elif n == 1: return 1 else: return fibo(n-1)+fibo(n-2)# 递归优化...原创 2020-02-01 14:55:22 · 99 阅读 · 0 评论 -
数据结构-单链表-python
__author__ = 'hp'class Node: """节点""" def __init__(self, item): self.item = item self.next = Noneclass SingleLinkedList: """单链表""" def __init__(self, node=None): ...原创 2020-01-30 21:31:05 · 105 阅读 · 0 评论