Actually it is GCD problem, share my Python


  • -1
    W
    class Solution(object):
        def canMeasureWater(self, x, y, z):
            """
            :type x: int
            :type y: int
            :type z: int
            :rtype: bool
            """
            x,y=max(x,y),min(x,y)
            if z==0:
                return True
            elif z>x+y:
                return False
            elif y==0:
                if x==z:
                    return True
                else:
                    return False
            while x%y>0:
                x,y=y,x%y
            if z%y==0:
                return True
            return False

Log in to reply
 

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