Leetcode 365 Solution

This article provides solution to leetcode question 365 (water-and-jug-problem)

https://leetcode.com/problems/water-and-jug-problem

Solution

class Solution {
    int gcd(int a, int b)
    {
        return b == 0 ? a : gcd(b, a % b);
    }

public:
    bool canMeasureWater(int x, int y, int z) {
        return z == 0 || (x + y >= z && z % gcd(x, y) == 0);
    }
};