zoukankan      html  css  js  c++  java
  • water-and-jug-problem

    以下这个解法也是参考了一些讨论:

    https://leetcode.com/discuss/110235/c-solution-using-euclidean-algorithm

    还有这个解释原理的,没有看懂:https://leetcode.com/discuss/110525/a-little-explanation-on-gcd-method

    class Solution {
        int gcd(int a, int b) {
            // below suppose a <= b
            // and if b < a, then b%a == b
            return a==0?b:gcd(b%a, a);
        }
    public:
        bool canMeasureWater(int x, int y, int z) {
            // notice, operator priority: % > == > && > ||
            // so below is equivalent to
            // (z == 0) || ((z <= (x+y)) && ((z % gcd(x,y)) == 0))
            return z == 0 || z <= (x+y) && z % gcd(x, y) == 0;
        }
    };
    31 / 31 test cases passed.
    Status: 

    Accepted

    Runtime: 0 ms
  • 相关阅读:
    css 面试学习
    关于CSS的图像放大问题的解决,需要借助jQuery等直接用css3设置
    DEBUG使用
    crontab
    od
    dumpe2fs
    mke2fs
    dd
    GDB
    rm
  • 原文地址:https://www.cnblogs.com/charlesblc/p/5620143.html
Copyright © 2011-2022 走看看