0321-2020-LEETCODE-365-ケトル問題 - 指定された容量とLianghuを水(GCDアルゴリズム)に水を注ぎます

コード出典:HTTPS://leetcode-cn.com/problems/water-and-jug-problem/comments/
考え方は:バイナリ線形方程式AX +溶液、xおよびyは整数= Z十分な条件によって最大公約数割り切れるzは、X + Y場合<zは直接、falseを返す最大公約数== 0が偽。

public boolean 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;
    }
    
公開された98元の記事 ウォンの賞賛0 ビュー2187

おすすめ

転載: blog.csdn.net/weixin_43221993/article/details/105030803