LeetCode 365水壶问题(java)

LeetCode 365水壶问题(java)_第1张图片

class Solution {
    public boolean canMeasureWater(int x, int y, int z) {
        // 判断特例
        if(x + y < z) 
            return false;
        if(x == z || y == z || x + y == z) 
            return true;
        return z % help(x, y) == 0;
        
    }
    public int help(int x, int y)  {
        if(x == 0) return y;
        int r = y%x;
        return help(r, x);
    }
}

你可能感兴趣的:(LeetCode刷题系列)