알고리즘/LeetCode
LeetCode 풀기 - 2169. Count Operations to Obtain Zero
앤테바
2022. 2. 26. 09:38
반응형
2169. Count Operations to Obtain Zero
https://leetcode.com/problems/count-operations-to-obtain-zero/
Count Operations to Obtain Zero - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
문제)
솔루션1) 재귀
의식의 흐름대로 풉니다.
class Solution:
def countOperations(self, num1: int, num2: int) -> int:
def recur(n1, n2, count):
if n1 == 0 or n2 == 0:
return count
if n1 > n2:
n1 -= n2
else:
n2 -= n1
return recur(n1, n2, count+1)
return recur(num1, num2, 0)
반응형