摘要: # 求子序列最大平均数def func(li: list, k: int): sum = 0 n = len(li) for i in range(k): sum += li[i] for i in range(k, n): temp = sum + li[i] - li[k - i] if tem 阅读全文
posted @ 2022-05-14 16:11 狒狒桑 阅读(17) 评论(0) 推荐(0) 编辑
摘要: # 排列硬币# 暴力求解def func1(n: int): for i in range(1, n + 1): n -= i if n < i: return i# 二分求解def func2(n: int): low = 1 high = n while low <= high: mid = ( 阅读全文
posted @ 2022-05-14 14:53 狒狒桑 阅读(25) 评论(0) 推荐(0) 编辑
摘要: # 暴力求解def func1(num: int): if num < 2: return num return func1(num - 1) + func1(num - 2)# 去重队列def recurse(li: list, num: int): if num == 0: return 0 i 阅读全文
posted @ 2022-05-14 11:48 狒狒桑 阅读(44) 评论(0) 推荐(0) 编辑
摘要: # 暴力算法def func1(li: list, target: int): for i in range(len(li)): for j in range(i + 1, len(li)): if li[i] + li[j] == target: return i, j return -1, -1 阅读全文
posted @ 2022-05-14 10:34 狒狒桑 阅读(32) 评论(0) 推荐(0) 编辑