**Leetcode 659. Split Array into Consecutive Subsequences
Posted Z-Pilgrim
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了**Leetcode 659. Split Array into Consecutive Subsequences相关的知识,希望对你有一定的参考价值。
https://leetcode.com/problems/split-array-into-consecutive-subsequences/description/
这个代码 技巧性太强了 参考了http://www.cnblogs.com/grandyang/p/7525821.html
基本思路就是,up维护数可能存在次数的上限,
class Solution
public:
bool isPossible(vector<int>& nums)
unordered_map< int, int > freq, up;
for (auto v : nums) freq[v]++;
for (auto v : nums)
if (!freq[v])continue;
if ( up[v] > 0 )
up[v] --;
up[v+1]++;
else if ( freq[v + 1] > 0 && freq[v + 2] > 0 )
freq[v+1]--;
freq[v+2]--;
up[v+3] ++;
else return false;
freq[v]--;
return true;
;
以上是关于**Leetcode 659. Split Array into Consecutive Subsequences的主要内容,如果未能解决你的问题,请参考以下文章
**Leetcode 659. Split Array into Consecutive Subsequences
leetcode659 Split Array into Consecutive Subsequences
[LeetCode] 659. Split Array into Consecutive Subsequences 将数组分割成连续子序列