Skip to content

Commit bb296a2

Browse files
committed
2350 solved.
1 parent fccb867 commit bb296a2

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
project(cpp_2350)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(cpp_2350 main.cpp)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// Source : https://leetcode.com/problems/shortest-impossible-sequence-of-rolls/
2+
/// Author : liuyubobobo
3+
/// Time : 2022-07-23
4+
5+
#include <iostream>
6+
#include <vector>
7+
8+
using namespace std;
9+
10+
11+
/// Greedy
12+
/// Time Complexity: O(n + k)
13+
/// Space Compelxity: O(k)
14+
class Solution {
15+
public:
16+
int shortestSequence(vector<int>& rolls, int k) {
17+
18+
vector<bool> used(k + 1, false);
19+
int cnt = 0, res = 0;
20+
for(int e: rolls){
21+
if(!used[e]){
22+
used[e] = true;
23+
cnt ++;
24+
if(cnt == k){
25+
res ++;
26+
used.assign(k + 1, false);
27+
cnt = 0;
28+
}
29+
}
30+
}
31+
return res;
32+
}
33+
};
34+
35+
36+
int main() {
37+
38+
return 0;
39+
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,7 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
22002200
| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand/) | [] | [C++](2001-2500/2347-Best-Poker-Hand/cpp-2347/) | | |
22012201
| 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays/) | [] | [C++](2001-2500/2348-Number-of-Zero-Filled-Subarrays/cpp-2348/) | | |
22022202
| 2349 | [Design a Number Container System](https://leetcode.com/problems/design-a-number-container-system/) | [] | [C++](2001-2500/2349-Design-a-Number-Container-System/cpp-2349/) | | |
2203+
| 2350 | [Shortest Impossible Sequence of Rolls](https://leetcode.com/problems/shortest-impossible-sequence-of-rolls/) | [] | [C++](2001-2500/2350-Shortest-Impossible-Sequence-of-Rolls/cpp-2350/) | | |
22032204
| | | | | | |
22042205

22052206
## 力扣中文站比赛

0 commit comments

Comments
 (0)