diff --git a/README.md b/README.md index 8554789c..6e8efe7b 100644 --- a/README.md +++ b/README.md @@ -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| \ No newline at end of file +|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| \ No newline at end of file diff --git a/src/1419-Minimum-Number-of-Frogs-Croaking/1419.cpp b/src/1419-Minimum-Number-of-Frogs-Croaking/1419.cpp new file mode 100644 index 00000000..1e617315 --- /dev/null +++ b/src/1419-Minimum-Number-of-Frogs-Croaking/1419.cpp @@ -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; + } +}; \ No newline at end of file diff --git a/src/1419-Minimum-Number-of-Frogs-Croaking/1419.go b/src/1419-Minimum-Number-of-Frogs-Croaking/1419.go new file mode 100644 index 00000000..335e9ab0 --- /dev/null +++ b/src/1419-Minimum-Number-of-Frogs-Croaking/1419.go @@ -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 +} \ No newline at end of file diff --git a/src/1419-Minimum-Number-of-Frogs-Croaking/1419.java b/src/1419-Minimum-Number-of-Frogs-Croaking/1419.java new file mode 100644 index 00000000..d48f1d3c --- /dev/null +++ b/src/1419-Minimum-Number-of-Frogs-Croaking/1419.java @@ -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; + } +} \ No newline at end of file diff --git a/src/1419-Minimum-Number-of-Frogs-Croaking/1419.js b/src/1419-Minimum-Number-of-Frogs-Croaking/1419.js new file mode 100644 index 00000000..7bf19842 --- /dev/null +++ b/src/1419-Minimum-Number-of-Frogs-Croaking/1419.js @@ -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; +}; \ No newline at end of file diff --git a/src/1419-Minimum-Number-of-Frogs-Croaking/1419.py b/src/1419-Minimum-Number-of-Frogs-Croaking/1419.py new file mode 100644 index 00000000..56826e6d --- /dev/null +++ b/src/1419-Minimum-Number-of-Frogs-Croaking/1419.py @@ -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 \ No newline at end of file diff --git a/src/addProb.py b/src/addProb.py index 5298f6e1..ce8f03d6 100644 --- a/src/addProb.py +++ b/src/addProb.py @@ -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']