C++ Py3 Euclidean Algorithm解Leetcode 2169 Count Operations to Obtain Zero
[Py3一行解請進]
[codes on Leetcode]https://leetcode.com/problems/count-operations-to-obtain-zero/solutions/7335752/recursion-with-div-with-remainderbeats-1-tcwc/
[輾轉相除euclidean algorithm list]https://www.youtube.com/watch?v=my83uM-J94U&list=PLYRlUBnWnd5KIWKDfP85BDs6aLq03_4e-
class Solution:
def countOperations(self, x: int, y: int) -> int:
return 0 if y==0 else x//y+self.countOperations(y, x%y)
沒有留言:
張貼留言
HTML 編輯器