1
2
3
4
5
6
7
8
|
class Solution:
def gcd(a,b):
if(b==0):
return a
else:
return gcd(b,a%b)
def findGCD(self, nums: List[int]) -> int:
return ( gcd(max(nums),min(nums)))
|
cs |
gcd구하는 함수는 재귀로 짜고
nums에서 가장 큰 값, 가장 작은 값의 gcd를 return 하면됩니다
주의할점은 a가 b보다 크거나 같아야됩니다
반응형
'python-algorithm' 카테고리의 다른 글
Leetcode 136. Single Number (0) | 2021.09.24 |
---|---|
Leetcode 1614. Maximum Nesting Depth of the Parentheses (0) | 2021.08.31 |
Leetcode 1588. Sum of All Odd Length Subarrays (0) | 2021.08.31 |
Leetcode 1720. Decode XORed Array (0) | 2021.08.31 |
Leetcode 682. Baseball Game (0) | 2021.08.30 |
댓글