Java solution in 0ms


  • -2
    F
    public class Solution {
        
        private int gcd(int x, int y){
            
            if(y == 0)
                return x;
            return gcd(y, x%y);
            
        }
        
        public boolean canMeasureWater(int x, int y, int z) {
            if(z > Math.max(x, y)) return false;
            return (z % gcd(x, y)) == 0;
        }
    }

  • 1
    J

    Why when z > Math.max(x, y), return false?

    If z = x + y, we could measure z litres, which is simply filling both two jugs.


Log in to reply
 

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