https://leetcode.com/problems/smallest-even-multiple/
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 |