g0301_0400.s0365_water_and_jug_problem.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java17 Show documentation
Show all versions of leetcode-in-java17 Show documentation
Java Solution for LeetCode algorithm problems, continually updating
package g0301_0400.s0365_water_and_jug_problem;
// #Medium #Math #Depth_First_Search #Breadth_First_Search
public class Solution {
private int gcd(int n1, int n2) {
if (n2 == 0) {
return n1;
}
return gcd(n2, n1 % n2);
}
public boolean canMeasureWater(int jug1, int jug2, int target) {
if (jug1 + jug2 < target) {
return false;
}
int gcd = gcd(jug1, jug2);
return target % gcd == 0;
}
}