A C# solution. Feedback welcome.


  • 0
    V
    public class Solution {
            public bool CanMeasureWater(int x, int y, int z) 
            {
                if (z == 0) return true;
                if (x + y < z) return false;
                int gcd = Gcd(x,y);
                if (gcd == 0) return false;
                return z % gcd == 0;
            }
    
            public int Gcd(int x, int y)
            {
                if (y == 0) return x;
                return Gcd(y, x % y);
            }
    }
    

Log in to reply
 

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