@jedihy I agree. 7 upvotes prove it, you achieved it with zero lines of code lol
I don't think so. If you have a deep think, you'll find it's easy.
Af first, I don't understand why my solution is wrong. At last, I know z should be smaller than x + y.
Aftering thinking about it, you can reduce it to the GCD problem, than it'll become so easy to slove.
and here is my code in Python:
def canMeasureWater(self, x, y, z):
:type x: int
:type y: int
:type z: int
ax + by = z
a(x + y) + (b-a)y = z
if z == 0:
a = 1 b = 1 if x > y: a = x b = y else: a = y b = x if b == 0: if a != 0 and z%a == 0: return True else: return False else: pass if z > a + b: return False else: pass tmp = b while tmp != 0: tmp = a%b a = b b = tmp if z%a == 0: return True else: return False
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.