-
You are given two integers num and t.
-
An integer x is said to be reachable if it can become equal to num by performing the following operations no more than t times:
-
Each operation increments or decrements the value of x by 1, and optionally increments or decrements the value of num by 1.
返回所有可达成数字中的最大值
. It can be shown that there exists at least one reachable number.
示例 1:
输入:num = 4, t = 1
输出:6
解释:最大可达成数字是 x = 6 ,执行下述操作可以使其等于 num :
- x 减少 1 ,同时 num 增加 1 。此时,x = 5 且 num = 5 。
可以证明不存在大于 6 的可达成数字。
示例 2:
输入:num = 3, t = 2
输出:7
解释:最大的可达成数字是 x = 7 ,执行下述操作可以使其等于 num :
- x 减少 1 ,同时 num 增加 1 。此时,x = 6 且 num = 4 。
- x 减少 1 ,同时 num 增加 1 。此时,x = 5 且 num = 5 。
可以证明不存在大于 7 的可达成数字。
提示:
1 <= num, t <= 50
class Solution {
public:
int theMaximumAchievableX(int num, int t) {
return num+2*t;
}
};