forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3327d6
commit 4b49020
Showing
7 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Solution { | ||
public: | ||
bool canMeasureWater(int x, int y, int z) { | ||
if (x + y < z) return false; | ||
if (x == 0 || y == 0) return z == 0 || x + y == z; | ||
return z % gcd(x, y) == 0; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
func canMeasureWater(x int, y int, z int) bool { | ||
if x + y < z { | ||
return false | ||
} | ||
|
||
if x == 0 || y == 0 { | ||
return z == 0 || x + y == z | ||
} | ||
return z % gcd(x, y) == 0 | ||
} | ||
|
||
func gcd(a, b int) int { | ||
if b == 0 { | ||
return a | ||
} | ||
return gcd(b, a % b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Solution { | ||
public boolean canMeasureWater(int x, int y, int z) { | ||
if (x + y < z) return false; | ||
if (x == 0 || y == 0) return z == 0 || x + y == z; | ||
return z % gcd(x, y) == 0; | ||
} | ||
|
||
private int gcd(int a, int b) { | ||
return b == 0 ? a : gcd(b, a % b); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var canMeasureWater = function(x, y, z) { | ||
let gcd = function(a, b) { | ||
return b == 0 ? a : gcd(b, a % b); | ||
} | ||
|
||
if (x + y < z) return false; | ||
if (x == 0 || y == 0) return z == 0 || x + y == z; | ||
return z % gcd(x, y) == 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Solution: | ||
def canMeasureWater(self, x: int, y: int, z: int) -> bool: | ||
if x + y < z: | ||
return False | ||
if x == 0 or y == 0: | ||
return z == 0 or x + y == z | ||
return z % math.gcd(x, y) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters