Count Operations to Obtain Zero

**You are given two non-negative integers num1 and num2.

In one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.

Return the number of operations required to make either num1 = 0 or num2 = 0.

class Solution {
public:
    int countOperations(int n1, int n2) {
        if(n1 == 0 || n2 == 0) return 0; //base case
        if(n1 == n2) return 1; //if numbers are equal
        if(n1 > n2) return countOperations(n1-n2, n2)+1; //else we return
        else return countOperations(n1, n2-n1)+1;
    }
};
Comments (2)