Smallest Even Multiple

easy math number theory

Problem

Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n. In other words, find the least common multiple of n and 2.

Inputn = 5
Output10
5 is odd, so the smallest number divisible by both 5 and 2 is 5 × 2 = 10.

def smallest_even_multiple(n):
    if n % 2 == 0:
        return n
    return n * 2
function smallestEvenMultiple(n) {
  if (n % 2 === 0) {
    return n;
  }
  return n * 2;
}
class Solution {
    public int smallestEvenMultiple(int n) {
        if (n % 2 == 0) {
            return n;
        }
        return n * 2;
    }
}
int smallestEvenMultiple(int n) {
    if (n % 2 == 0) {
        return n;
    }
    return n * 2;
}
Time: O(1) Space: O(1)