Share my C++ solution


  • 0
    V
    class Solution {
    public:
        int gcd(int x, int y)
        {
            if (y == 0)
                return x;
            
            return gcd(y, x % y);
        }
    
        bool canMeasureWater(int x, int y, int z) {
            if (z == 0)
                return true;
            if (x + y < z)
                return false;
                
            int t = gcd(x, y);
            if (z % t == 0)
                return true;
            
            return false;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.