Python/algorithm

[Leetcode] 2413. Smallest Even Multiple

baecode 2022. 12. 31. 19:34
반응형

Problem

이번 문제는 어렵게 써놧지만 최소공배수를 구하는 문제이다 

 

나의 풀이

class Solution:
    def smallestEvenMultiple(self, n: int) -> int:
        import math
        return math.lcm(n,2)

        # for i in range(max(a, b), (a * b) + 1):
        #     if i % a == 0 and i % b == 0:
        #         return i

파이썬 MATH에 있는 LCM을 사용하여서 문제를 풀었고 아래에 있는 풀이가 최소 공배수를 푸는 공식이다.

반응형