-
Notifications
You must be signed in to change notification settings - Fork 0
/
659.hpp
41 lines (34 loc) · 893 Bytes
/
659.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef LEETCODE_659_HPP
#define LEETCODE_659_HPP
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <stack>
#include <string>
using namespace std;
class Solution {
public:
bool isPossible(vector<int> &nums) {
unordered_map<int, priority_queue<int, vector<int>, greater<int >>> backs;
int need_more = 0;
for (int num : nums) {
if (backs[num - 1].empty()) {
backs[num].push(1);
need_more++;
} else {
int count = backs[num - 1].top();
backs[num - 1].pop();
backs[num].push(++count);
if (count == 3)
need_more--;
}
}
return need_more == 0;
}
};
#endif //LEETCODE_659_HPP