The mathematical solution


  • 1
    R

    Detailed explanation can be find at this link

    class Solution {
    public:
        bool canMeasureWater(int x, int y, int z) {
            if (x + y < z) return false;
            if (z <= 0 || x == z || y == z || x + y == z) return true;
            return  (__gcd(x, y) == 1);
        }
    };
    

Log in to reply
 

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