2413:最小偶倍数
This commit is contained in:
parent
7a721c901e
commit
4177c5a147
46
src/main/java/leetcode/editor/cn/SmallestEvenMultiple.java
Normal file
46
src/main/java/leetcode/editor/cn/SmallestEvenMultiple.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
//给你一个正整数 n ,返回 2 和 n 的最小公倍数(正整数)。
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 示例 1:
|
||||||
|
//
|
||||||
|
// 输入:n = 5
|
||||||
|
//输出:10
|
||||||
|
//解释:5 和 2 的最小公倍数是 10 。
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 示例 2:
|
||||||
|
//
|
||||||
|
// 输入:n = 6
|
||||||
|
//输出:6
|
||||||
|
//解释:6 和 2 的最小公倍数是 6 。注意数字会是它自身的倍数。
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 提示:
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 1 <= n <= 150
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 👍 5 👎 0
|
||||||
|
|
||||||
|
package leetcode.editor.cn;
|
||||||
|
|
||||||
|
//2413:最小偶倍数
|
||||||
|
public class SmallestEvenMultiple {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 测试代码
|
||||||
|
Solution solution = new SmallestEvenMultiple().new Solution();
|
||||||
|
}
|
||||||
|
|
||||||
|
//leetcode submit region begin(Prohibit modification and deletion)
|
||||||
|
class Solution {
|
||||||
|
public int smallestEvenMultiple(int n) {
|
||||||
|
return n % 2 == 0 ? n : n * 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//leetcode submit region end(Prohibit modification and deletion)
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
给你一个正整数 <code>n</code> ,返回 <code>2</code><em> </em>和<em> </em><code>n</code> 的最小公倍数(正整数)。
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>n = 5
|
||||||
|
<strong>输出:</strong>10
|
||||||
|
<strong>解释:</strong>5 和 2 的最小公倍数是 10 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>n = 6
|
||||||
|
<strong>输出:</strong>6
|
||||||
|
<strong>解释:</strong>6 和 2 的最小公倍数是 6 。注意数字会是它自身的倍数。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n <= 150</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div><li>👍 5</li><li>👎 0</li></div>
|
Loading…
Reference in New Issue
Block a user