本文主要是介绍Day70力扣打卡,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
打卡记录
收集足够苹果的最小花园周长(找规律 + 二分)
链接
class Solution:def minimumPerimeter(self, neededApples: int) -> int:l, r = 1, 10 ** 5while l < r:mid = (l + r) >> 1if 2 * (2 * (mid ** 3) + 3 * (mid ** 2) + mid) >= neededApples:r = midelse:l = mid + 1return 8 * l
转换字符串的最小成本 I(矩阵间的Floyd)
链接
class Solution:def minimumCost(self, source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:dis = [[inf] * 26 for _ in range(26)]for i in range(26):dis[i][i] = 0for x, y, c in zip(original, changed, cost):x = ord(x) - ord('a')y = ord(y) - ord('a')dis[x][y] = min(dis[x][y], c)for k in range(26):for i in range(26):for j in range(26):dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])ans = sum(dis[ord(x) - ord('a')][ord(y) - ord('a')] for x, y in zip(source, target))return ans if ans < inf else -1
这篇关于Day70力扣打卡的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!