Simple Java Solution


  • -1
    S
    public int findGreatestCommonElement(int x, int y) {
        int z = x % y;
        if (z == 0) return y;
        else return findGreatestCommonElement(y, z);
    }
    public boolean canMeasureWater(int x, int y, int z) {
        if (x + y < z) return false;
        if (x == 0) return z <= y;
        else if (y == 0) return z <= x;
        return z % findGreatestCommonElement(x, y) == 0;
    }

Log in to reply
 

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