leetcode 耗时100 1716. Calculate Money in Leetcode Bank
2026/8/12 12:41:33 网站建设 项目流程

Problem: 1716. 计算力扣银行的钱

等比数列求和的,28,28 + 7, 28 + 7 * 2,最后累加上余数

耗时100,

Code

class Solution { public: int totalMoney(int n) { int id = n / 7; int sum = (28 + 28 + max(0, (id - 1)*7)) * id / 2; int now = 1 + id; for(int i = id * 7; i <n; i++ ) { sum += (now++); } return sum; } };

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询