Python solution without GCD


  • 0
    D
    class Solution(object):
        def canMeasureWater(self, x, y, z):
            small = min(x, y)
            big = max(x, y)
            if z == 0:
                return True
            if z > small + big:
                return False
            elif small == 0:
                return big == z
            elif big % small == 0:
                return z % small == 0
            elif (big & 1) == 0 and (small & 1) == 0:
                return (z & 1) == 0
            else:
                return True

  • 0

    Doesn't work, fails for example x=6, y=9, z=1.


  • 0

    Thanks, I have added this test case.


Log in to reply
 

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