Skip to content

Commit

Permalink
add 1419
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed Apr 22, 2020
1 parent d4486ef commit b836fc1
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -713,4 +713,5 @@ LeetCode
|1415|[The k-th Lexicographical String of All Happy Strings of Length n](https://leetcode.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n/)|c|[c++](./src/1415-The-k-th-Lexicographical-String-of-All-Happy-Strings-of-Length-n/1415.cpp)|[python](./src/1415-The-k-th-Lexicographical-String-of-All-Happy-Strings-of-Length-n/1415.py)|[go](./src/1415-The-k-th-Lexicographical-String-of-All-Happy-Strings-of-Length-n/1415.go)|[js](./src/1415-The-k-th-Lexicographical-String-of-All-Happy-Strings-of-Length-n/1415.js)|[java](./src/1415-The-k-th-Lexicographical-String-of-All-Happy-Strings-of-Length-n/1415.java)|Medium|
|1416|[Restore The Array](https://leetcode.com/problems/restore-the-array/)|c|[c++](./src/1416-Restore-The-Array/1416.cpp)|[python](./src/1416-Restore-The-Array/1416.py)|[go](./src/1416-Restore-The-Array/1416.go)|[js](./src/1416-Restore-The-Array/1416.js)|[java](./src/1416-Restore-The-Array/1416.java)|Hard|
|1417|[Reformat The String](https://leetcode.com/problems/reformat-the-string/)|c|[c++](./src/1417-Reformat-The-String/1417.cpp)|[python](./src/1417-Reformat-The-String/1417.py)|[go](./src/1417-Reformat-The-String/1417.go)|[js](./src/1417-Reformat-The-String/1417.js)|[java](./src/1417-Reformat-The-String/1417.java)|Easy|
|1418|[Display Table of Food Orders in a Restaurant](https://leetcode.com/problems/display-table-of-food-orders-in-a-restaurant/)|c|[c++](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.cpp)|[python](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.py)|[go](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.go)|[js](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.js)|[java](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.java)|Medium|
|1418|[Display Table of Food Orders in a Restaurant](https://leetcode.com/problems/display-table-of-food-orders-in-a-restaurant/)|c|[c++](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.cpp)|[python](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.py)|[go](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.go)|[js](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.js)|[java](./src/1418-Display-Table-of-Food-Orders-in-a-Restaurant/1418.java)|Medium|
|1419|[Minimum Number of Frogs Croaking](https://leetcode.com/problems/minimum-number-of-frogs-croaking/)|c|[c++](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.cpp)|[python](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.py)|[go](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.go)|[js](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.js)|[java](./src/1419-Minimum-Number-of-Frogs-Croaking/1419.java)|Medium|
17 changes: 17 additions & 0 deletions src/1419-Minimum-Number-of-Frogs-Croaking/1419.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public:
int minNumberOfFrogs(string cr) {
int c = 0, r = 0, a = 0, k = 0, o = 0, frogs = 0, res = 0;
for(char i : cr) {
if (i=='c') {c++; frogs++;}
else if (i=='r') r++;
else if (i=='o') o++;
else if (i=='a') a++;
else {k++; frogs--;}
res = max(res, frogs);
if (c < r || r < o || o < a || a < k) return -1;
}
if (c == r && c == o && c == a && c == k) return res;
return -1;
}
};
35 changes: 35 additions & 0 deletions src/1419-Minimum-Number-of-Frogs-Croaking/1419.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
func minNumberOfFrogs(cr string) int {
res, frogs := 0, 0
st := make([]int, 5)
for _, i := range []byte(cr) {
if i == 'c' {
st[0]++
frogs++
} else if i == 'r' {
st[1]++
} else if i == 'o' {
st[2]++
} else if i == 'a' {
st[3]++
} else {
st[4]++
frogs--
}
res = max(res, frogs)
if st[0] < st[1] || st[1] < st[2] || st[2] < st[3] || st[3] < st[4] {
return -1
}
}

if st[0] == st[1] && st[1] == st[2] && st[2] == st[3] && st[3] == st[4] {
return res
}
return -1
}

func max(a, b int) int {
if a > b {
return a
}
return b
}
16 changes: 16 additions & 0 deletions src/1419-Minimum-Number-of-Frogs-Croaking/1419.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public int minNumberOfFrogs(String cr) {
int c = 0, r = 0, a = 0, k = 0, o = 0, frogs = 0, res = 0;
for(char i : cr.toCharArray()) {
if (i=='c') {c++; frogs++;}
else if (i=='r') r++;
else if (i=='o') o++;
else if (i=='a') a++;
else {k++; frogs--;}
res = Math.max(res, frogs);
if (c < r || r < o || o < a || a < k) return -1;
}
if (c == r && c == o && c == a && c == k) return res;
return -1;
}
}
14 changes: 14 additions & 0 deletions src/1419-Minimum-Number-of-Frogs-Croaking/1419.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var minNumberOfFrogs = function(cr) {
let c = 0, r = 0, a = 0, k = 0, o = 0, frogs = 0, res = 0;
for(let i of cr) {
if (i=='c') {c++; frogs++;}
else if (i=='r') r++;
else if (i=='o') o++;
else if (i=='a') a++;
else {k++; frogs--;}
res = Math.max(res, frogs);
if (c < r || r < o || o < a || a < k) return -1;
}
if (c == r && c == o && c == a && c == k) return res;
return -1;
};
23 changes: 23 additions & 0 deletions src/1419-Minimum-Number-of-Frogs-Croaking/1419.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution:
def minNumberOfFrogs(self, cr: str) -> int:
res, frogs = 0, 0
st = [0] * 5
for i in cr:
if i == 'c':
st[0] += 1
frogs += 1
elif i == 'r':
st[1] += 1
elif i == 'o':
st[2] += 1
elif i == 'a':
st[3] += 1
else:
st[4] += 1
frogs -= 1
res = max(res, frogs)
if not (st[0] >= st[1] >= st[2] >= st[3] >= st[4]): return -1

if st[0] == st[1] == st[2] == st[3] == st[4]:
return res
return -1
6 changes: 3 additions & 3 deletions src/addProb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import os, bisect

# 题目名称
name = "Display Table of Food Orders in a Restaurant"
ID = 1418
url = "https://leetcode.com/problems/display-table-of-food-orders-in-a-restaurant/"
name = "Minimum Number of Frogs Croaking"
ID = 1419
url = "https://leetcode.com/problems/minimum-number-of-frogs-croaking/"
difficult = "Medium"
prog = ['c', 'cpp', 'py', 'go', 'js', 'java']

Expand Down

0 comments on commit b836fc1

Please sign in to comment.