力扣第365题 水壶问题
class Solution {
public:
int func(int x, int y)
{
if (x < y)
{
x = x + y;
y = x - y;
x = x - y;
}
int temp = 0;
while (y != 0)
{
temp = x % y;
x = y;
y = temp;
}
return x;
}
bool canMeasureWater(int x, int y, int z) {
if (x + y < z) return false;
if (x == 0 || y == 0) return z == 0 || x + y == z;
return z % func(x, y) == 0;
}
};