返回介绍

solution / 1700-1799 / 1716.Calculate Money in Leetcode Bank / README_EN

发布于 2024-06-17 01:03:15 字数 2757 浏览 0 评论 0 收藏 0

1716. Calculate Money in Leetcode Bank

中文文档

Description

Hercy wants to save money for his first car. He puts money in the Leetcode bank every day.

He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sunday, he will put in $1 more than the day before. On every subsequent Monday, he will put in $1 more than the previous Monday.

Given n, return _the total amount of money he will have in the Leetcode bank at the end of the _nth_ day._

 

Example 1:

Input: n = 4
Output: 10
Explanation: After the 4th day, the total is 1 + 2 + 3 + 4 = 10.

Example 2:

Input: n = 10
Output: 37
Explanation: After the 10th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37. Notice that on the 2nd Monday, Hercy only puts in $2.

Example 3:

Input: n = 20
Output: 96
Explanation: After the 20th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96.

 

Constraints:

  • 1 <= n <= 1000

Solutions

Solution 1

class Solution:
  def totalMoney(self, n: int) -> int:
    a, b = divmod(n, 7)
    return (28 + 28 + 7 * (a - 1)) * a // 2 + (a * 2 + b + 1) * b // 2
class Solution {
  public int totalMoney(int n) {
    int a = n / 7, b = n % 7;
    return (28 + 28 + 7 * (a - 1)) * a / 2 + (a * 2 + b + 1) * b / 2;
  }
}
class Solution {
public:
  int totalMoney(int n) {
    int a = n / 7, b = n % 7;
    return (28 + 28 + 7 * (a - 1)) * a / 2 + (a * 2 + b + 1) * b / 2;
  }
};
func totalMoney(n int) int {
  a, b := n/7, n%7
  return (28+28+7*(a-1))*a/2 + (a*2+b+1)*b/2
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文