Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool isPossible(vector<int>& nums) {
- unordered_map <int , int > freq , extend;
- for (int i = 0 ; i < nums.size(); i++)
- {
- freq[nums[i]] ++;
- }
- for (int i = 0 ; i < nums.size(); i++)
- {
- int cur = nums[i];
- if (freq[cur] == 0)
- continue;
- if (extend[cur] > 0)
- {
- freq[cur]--;
- extend[cur]--;
- extend[cur + 1]++;
- }
- else if (freq[cur + 1] > 0 && freq[cur + 2] > 0)
- {
- freq[cur]--;
- freq[cur + 1]--;
- freq[cur + 2]--;
- extend[cur + 3]++;
- }
- else
- return false;
- }
- return true;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement