美文网首页
Water and Jug Problem

Water and Jug Problem

作者: 我叫胆小我喜欢小心 | 来源:发表于2017-05-05 09:32 被阅读11次

    题目来源
    一道用固定容量的杯子来获得对应体积的水的题目,感觉很熟悉,但是不知道怎么做。
    发现是道数学题,代码如下:

    class Solution {
    public:
        bool canMeasureWater(int x, int y, int z) {
            long long sum = x + y;
            if (sum >= z && (z == 0 || z % __gcd(x, y) == 0))
                return true;
            return false;
        }
    };
    

    相关文章

      网友评论

          本文标题:Water and Jug Problem

          本文链接:https://www.haomeiwen.com/subject/fgjjtxtx.html