https://leetcode.com/problems/smallest-even-multiple/
Smallest Even Multiple - LeetCode
Can you solve this real interview question? Smallest Even Multiple - Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n. Example 1: Input: n = 5 Output: 10 Explanation: The smallest multiple of both 5 and
leetcode.com
Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.
gcd / lcm 문제
class Solution {
    public int smallestEvenMultiple(int n) {
        return (2 * n) / gcd(2, n);
    }
    public int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
}'Algorithm > LeetCode' 카테고리의 다른 글
| 1859. Sorting the Sentence (0) | 2023.03.31 | 
|---|---|
| 2160. Minimum Sum of Four Digit Number After Splitting Digits (0) | 2023.03.31 | 
| 2469. Convert the Temperature (0) | 2023.03.30 | 
| 1920. Build Array from Permutation (0) | 2023.03.30 | 
| 1929. Concatenation of Array (0) | 2023.03.30 |