comments | difficulty | edit_url | rating | source | tags | |
---|---|---|---|---|---|---|
true |
Easy |
1191 |
Weekly Contest 353 Q1 |
|
Given two integers, num
and t
. A number is achievable if it can become equal to num
after applying the following operation:
- Increase or decrease the number by
1
, and simultaneously increase or decreasenum
by1
.
Return the maximum achievable number after applying the operation at most t
times.
Example 1:
Input: num = 4, t = 1
Output: 6
Explanation:
Apply the following operation once to make the maximum achievable number equal to num
:
- Decrease the maximum achievable number by 1, and increase
num
by 1.
Example 2:
Input: num = 3, t = 2
Output: 7
Explanation:
Apply the following operation twice to make the maximum achievable number equal to num
:
- Decrease the maximum achievable number by 1, and increase
num
by 1.
Constraints:
1 <= num, t <= 50
Notice that every time we can decrease
The time complexity is
class Solution:
def theMaximumAchievableX(self, num: int, t: int) -> int:
return num + t * 2
class Solution {
public int theMaximumAchievableX(int num, int t) {
return num + t * 2;
}
}
class Solution {
public:
int theMaximumAchievableX(int num, int t) {
return num + t * 2;
}
};
func theMaximumAchievableX(num int, t int) int {
return num + t*2
}
function theMaximumAchievableX(num: number, t: number): number {
return num + t * 2;
}