-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Open
@feiquan123
Description
func LoopAdd(cnt, v0, step int) int { result := v0 for i := 0; i < cnt; i++ { result += step } return result }
比如 1+2+...+100 等差数列可以这样计算 LoopAdd(100, 1, 1),而 10+8+...+0 等差数列则可以这样计算 LoopAdd(5, 10, -2)。
问题描述
按这个算法
LoopAdd(100, 1, 1) = 101 期望:5050
LoopAdd(5, 10, -2) = 0 期望:30