Python solution beat 99.3%


  • 1
    L
    class Solution(object):
        def canMeasureWater(self, x, y, z):
            dmax = max(x, y)
            dmin = min(x, y)
            if dmin ==0 and dmax ==z or z ==0:
                return True
            elif dmin == 0 and dmax != z or x+y<z:
                return False
            resid = self.gcd(dmax, dmin)
            return True if z % resid == 0 else False
    
        def gcd(self, x, y):
            return x if y == 0  else self.gcd(y, x%y)
    

  • 0
    1

    Thank you very much !


Log in to reply
 

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