Ugly short c++ soluton


  • 1
    M
    class Solution {
    public:
        bool canMeasureWater(int x, int y, int z) {
            if(z > x+y) return false;
            while(x&&(x^=y^=x^=y%=x));
            return x+y == 0 || z%y == 0;
        }
    };
    

  • 0
    F

    if z = 10, x =2, y=3, it will return false,
    but it should return true, because z % (x+y) is 0, right?


  • 0
    F

    my bad:
    you must have z liters of water contained within one or both buckets by the end


Log in to reply
 

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