659. Split Array into Consecutive Subsequences
题目描述
You are given an integer array sorted in ascending order (may contain duplicates), you need to split them into several subsequences, where each subsequences consist of at least 3 consecutive integers. Return whether you can make such a split.
Example 1:
|
|
Example 2:
|
|
Example 3:
|
|
Note:
The length of the input is in range of [1, 10000]
题目大意
将一有序数组,拆分成多个递增子序列。(每个子序列至少三个)
解题思路
一个字典
dict
记录剩余num
的个数
另一个字典tail
则记录当前的num
是否可以被拼接到之前的子序列。
如果不可以则重新启动一个新的序列,但是新的序列需要满足至少有三个num
。
代码
|
|