Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.
a * jug1Capacity + b * jug2Capacity = targetCapacity
targetCapacity
能被 a 和 b 的最大公约数整除class Solution {
public:
bool canMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity) {
if (targetCapacity > jug1Capacity + jug2Capacity) {
return false;
}
return targetCapacity % gcd(jug1Capacity, jug2Capacity) == 0;
}
};