https://leetcode.com/problems/water-and-jug-problem/#/description
给两个杯子容量分别是x和y,判断能否量出容量z
public 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 % gcd(x, y) == 0;
}
private int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
}