程式語言 - LeetCode - CPP - 365. Water and Jug Problem



題目:


解答:

class Solution {
public:
    bool canMeasureWater(int x, int y, int target) {
        if (target > x + y) {
            return false;
        }
        if (target == 0) {
            return true;
        }

        return target % gcd(x, y) == 0;
    }
};