leetcode 365. Water and Jug Problem

来源:互联网 发布:金思维软件 编辑:程序博客网 时间:2024/06/04 23:27
class Solution {public:    bool canMeasureWater(int x, int y, int z)     {        if(z == 0)        {            return true;        }        if(x+y < z)        {            return false;        }        return z%gcd(x,y) == 0;    }private:    int gcd(int x,int y)    {        while(y)        {            auto tmp = y;            y = x%y;            x = tmp;        }        return x;    }};
原创粉丝点击