Add solution 1603、1608、1700、1710、1716、1720、1725、1732、1736、1742、1748、1752、1758

This commit is contained in:
YDZ
2021-02-15 13:20:24 +08:00
parent 9de9488b04
commit 917d613465
74 changed files with 3220 additions and 304 deletions

View File

@ -0,0 +1,13 @@
package leetcode
func totalMoney(n int) int {
res := 0
for tmp, count := 1, 7; n > 0; tmp, count = tmp+1, 7 {
for m := tmp; n > 0 && count > 0; m++ {
res += m
n--
count--
}
}
return res
}

View File

@ -0,0 +1,52 @@
package leetcode
import (
"fmt"
"testing"
)
type question1716 struct {
para1716
ans1716
}
// para 是参数
// one 代表第一个参数
type para1716 struct {
n int
}
// ans 是答案
// one 代表第一个答案
type ans1716 struct {
one int
}
func Test_Problem1716(t *testing.T) {
qs := []question1716{
{
para1716{4},
ans1716{10},
},
{
para1716{10},
ans1716{37},
},
{
para1716{20},
ans1716{96},
},
}
fmt.Printf("------------------------Leetcode Problem 1716------------------------\n")
for _, q := range qs {
_, p := q.ans1716, q.para1716
fmt.Printf("【input】:%v 【output】:%v\n", p, totalMoney(p.n))
}
fmt.Printf("\n\n\n")
}

View File

@ -0,0 +1,64 @@
# [1716. Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank/)
## 题目
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`
## 题目大意
Hercy 想要为购买第一辆车存钱。他 每天 都往力扣银行里存钱。最开始,他在周一的时候存入 1 块钱。从周二到周日他每天都比前一天多存入 1 块钱。在接下来每一个周一他都会比 前一个周一 多存入 1 块钱。给你 n 请你返回在第 n 天结束的时候他在力扣银行总共存了多少块钱。
## 解题思路
- 简单题。按照题意写 2 层循环即可。
## 代码
```go
package leetcode
func totalMoney(n int) int {
res := 0
for tmp, count := 1, 7; n > 0; tmp, count = tmp+1, 7 {
for m := tmp; n > 0 && count > 0; m++ {
res += m
n--
count--
}
}
return res
}
```