题目来源:
leetcode题目,网址:2413. 最小偶倍数 - 力扣(LeetCode)
解题思路:
若 n 是偶数,n 即为所求;若 n 是奇数,2*n 即为所求。
解题代码:
class Solution {
public int smallestEvenMultiple(int n) {
return n%2==0?n:2*n;
}
}
总结:
无。
题目来源:
leetcode题目,网址:2413. 最小偶倍数 - 力扣(LeetCode)
解题思路:
若 n 是偶数,n 即为所求;若 n 是奇数,2*n 即为所求。
解题代码:
class Solution {
public int smallestEvenMultiple(int n) {
return n%2==0?n:2*n;
}
}
总结:
无。