当前位置: 代码迷 >> 综合 >> LeetCode 1716. 计算力扣银行的钱
  详细解决方案

LeetCode 1716. 计算力扣银行的钱

热度:4   发布时间:2023-12-22 07:41:34.0

题目链接:

力扣icon-default.png?t=M276https://leetcode-cn.com/problems/calculate-money-in-leetcode-bank/

【分析】先除,看看多少个整周的,再取余,把剩下几天的加进去。

class Solution {public int totalMoney(int n) {int ans = 0, i;int t = n / 7;int k = n % 7;int w = 28;for(i = 0; i < t; i++){ans += w;w += 7;}k = t + k;for(i = t + 1; i <= k; i++){ans += i;}return ans;}
}