반응형
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을 사용하여서 문제를 풀었고 아래에 있는 풀이가 최소 공배수를 푸는 공식이다.
반응형
'Python > algorithm' 카테고리의 다른 글
[Leetcode] 1281. Subtract the Product and Sum of Digits of an Integer (2) | 2023.01.04 |
---|---|
[Leetcode] 1431. Kids With the Greatest Number of Candies (1) | 2023.01.02 |
[Leetcode] 1603. Design Parking System (1) | 2022.12.30 |
[Leetcode] 2114. Maximum Number of Words Found in Sentences (0) | 2022.12.29 |
[Leetcode] 771. Jewels and Stones (0) | 2022.12.27 |