Skip to content

Commit ca8165c

Browse files
committed
✨2769.找出最大的可达成数字
1 parent 51cd488 commit ca8165c

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
- [2739.总行驶距离](leetcode/easy/t2739/solution.go)
141141
- [2760.最长奇偶子数组](leetcode/easy/t2760/solution.go)
142142
- [2765.最长交替子数组](leetcode/easy/t2765/solution.go)
143+
- [2769.找出最大的可达成数字](leetcode/easy/t2769/solution.go)
143144
- [2798.满足目标工作时长的员工数目](leetcode/easy/t2798/solution.go)
144145
- [2894.分类求和并做差](leetcode/easy/t2894/solution.go)
145146
- [2908.元素和最小的山形三元组 I](leetcode/easy/t2908/solution.go)

leetcode/easy/t2769/solution.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package t2769
2+
3+
// 2769. 找出最大的可达成数字
4+
// https://leetcode.cn/problems/find-the-maximum-achievable-number
5+
func theMaximumAchievableX(num int, t int) int {
6+
return num + t*2
7+
}

leetcode/easy/t2769/solution_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package t2769
2+
3+
import "testing"
4+
5+
func TestTheMaximumAchievableX(t *testing.T) {
6+
tests := []struct {
7+
name string
8+
num int
9+
t int
10+
want int
11+
}{
12+
{
13+
name: "Case 1",
14+
num: 4,
15+
t: 1,
16+
want: 6,
17+
},
18+
{
19+
name: "Case 2",
20+
num: 3,
21+
t: 2,
22+
want: 7,
23+
},
24+
}
25+
for _, tt := range tests {
26+
t.Run(tt.name, func(t *testing.T) {
27+
if got := theMaximumAchievableX(tt.num, tt.t); got != tt.want {
28+
t.Errorf("theMaximumAchievableX() = %v, want %v", got, tt.want)
29+
}
30+
})
31+
}
32+
}

0 commit comments

Comments
 (0)