Skip to content

Commit

Permalink
add 365
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed Mar 26, 2020
1 parent f3327d6 commit 4b49020
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ LeetCode
|0349|[Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays/) | c | [c++](./src/0349-Intersection-of-Two-Arrays/0349.cpp) |[python](./src/0349-Intersection-of-Two-Arrays/0349.py)||| |Easy|
|0350|[Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/) | c | [c++](./src/0350-Intersection-of-Two-Arrays-II/0350.cpp) |[python](./src/0350-Intersection-of-Two-Arrays-II/0350.py)||| |Easy|
|0354|[Russian Doll Envelopes](https://leetcode.com/problems/russian-doll-envelopes/) | c | [c++](./src/0354-Russian-Doll-Envelopes/0354.cpp) |[python](./src/0354-Russian-Doll-Envelopes/0354.py)||| |Hard|
|0365|[Water and Jug Problem](https://leetcode.com/problems/water-and-jug-problem/)|c|[c++](./src/0365-Water-and-Jug-Problem/0365.cpp)|[python](./src/0365-Water-and-Jug-Problem/0365.py)|[go](./src/0365-Water-and-Jug-Problem/0365.go)|[js](./src/0365-Water-and-Jug-Problem/0365.js)|[java](./src/0365-Water-and-Jug-Problem/0365.java)|Medium|
|0371|[Sum of Two Integers](https://leetcode.com/problems/russian-doll-envelopes/) | c | [c++](./src/0371-Sum-of-Two-Integers/0371.cpp) |[python](./src/0371-Sum-of-Two-Integers/0371.py)||| |Easy|
|0377|[Combination Sum IV](https://leetcode.com/problems/combination-sum-iv/) | c | [c++](./src/0377-Combination-Sum-IV/0377.cpp) |[python](./src/0377-Combination-Sum-IV/0377.py)||| |Medium|
|0389|[Find the Difference](https://leetcode.com/problems/find-the-difference/) | c | [c++](./src/0389-Find-the-Difference/0389.cpp) |[python](./src/0389-Find-the-Difference/0389.py)||| |Easy|
Expand Down
8 changes: 8 additions & 0 deletions src/0365-Water-and-Jug-Problem/0365.cpp
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;
}
};
17 changes: 17 additions & 0 deletions src/0365-Water-and-Jug-Problem/0365.go
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)
}
11 changes: 11 additions & 0 deletions src/0365-Water-and-Jug-Problem/0365.java
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);
}
}
9 changes: 9 additions & 0 deletions src/0365-Water-and-Jug-Problem/0365.js
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;
};
7 changes: 7 additions & 0 deletions src/0365-Water-and-Jug-Problem/0365.py
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
8 changes: 4 additions & 4 deletions src/addProb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import os, bisect

# 题目名称
name = "Longest Happy Prefix"
ID = 1392
url = "https://leetcode.com/problems/longest-happy-prefix/"
difficult = "Hard"
name = "Water and Jug Problem"
ID = 365
url = "https://leetcode.com/problems/water-and-jug-problem/"
difficult = "Medium"
prog = ['c', 'cpp', 'py', 'go', 'js', 'java']


Expand Down

0 comments on commit 4b49020

Please sign in to comment.