摘要: # 求三个数最大乘积# 思路:三个数都是正数,则取最大三个数;三个数都是复数,也取最大三个数;有正有负,取最小的2个负数、最大的正数# 排序求解from math import infdef func1(li:list): li.sort() return max(li[0]*li[1]*li[-1 阅读全文
posted @ 2022-05-13 23:37 狒狒桑 阅读(126) 评论(0) 推荐(0) 编辑
摘要: # x平方根# 暴力求解def func1(x: int): i = 1 while True: if i * i < x: i += 1 elif i * i == x: return i else: return i - 1# 二分查找def func2(x: int): index = 0 l 阅读全文
posted @ 2022-05-13 23:11 狒狒桑 阅读(21) 评论(0) 推荐(0) 编辑
摘要: def fun1(li: list): if len(li) == 1: return 1 sum_num = sum(li) res = 0 for i in range(len(li)): res += li[i] if res == sum_num: return i sum_num -= l 阅读全文
posted @ 2022-05-13 22:20 狒狒桑 阅读(15) 评论(0) 推荐(0) 编辑
摘要: # 有序数列def fun1(li: list): return len(set(li))def fun2(li: list): new = [] for i in li: if i not in new: new.append(i) return len(new)def fun3(li: list 阅读全文
posted @ 2022-05-13 19:35 狒狒桑 阅读(21) 评论(0) 推荐(0) 编辑
摘要: # 判断是否素数def premi(n): if n < 2: return False import math for i in range(2, math.floor(math.sqrt(n)) + 1): if n % i == 0: return False return True# 统计素 阅读全文
posted @ 2022-05-13 19:05 狒狒桑 阅读(25) 评论(0) 推荐(0) 编辑