计算力扣银行的钱
难度:简单
在这里插入图片描述
美好的周六当然是简单题(●’◡’●)
存的钱 = n-1周存的钱 + 当前第n周存的钱
代码如下:

	public int totalMoney(int n) {
        int a = n/7;
        int b = n%7;
        int res = 0;
        //n-1周存的钱
        for(int i = 0;i<a;i++){
            res += 28 + 7 * i;
        }
        //当前第n周存的钱
        for(int j = 1; j<=b;j++){
            res += a+j;
        }
        return res;
    }

执行结果:成功
在这里插入图片描述

更多推荐