Count Operations to Obtain Zero
给两个数字, 大减小, 求多少步能减到0.
1 2 3 4 5 6 7 8 9 10 |
class Solution { public int countOperations(int a, int b) { if(a == 0 || b == 0) return 0; if(a > b) return countOperations(a - b, b) + 1; else return countOperations(a, b - a) + 1; } } |