[LeetCode] Smallest Even Multiple

2413. Smallest Even Multiple

Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.

1
2
3
4
5
6
7
8
class Solution {
public:
int smallestEvenMultiple(int n) {
if(n%2 == 0) return n;
return 2 * n;
}
};

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/09/18/PS/LeetCode/smallest-even-multiple/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.