# # 【LeetCode】659. Split Array into Consecutive Subsequences 解题报告（Python）

## # 题目描述：

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:

``````Input: [1,2,3,3,4,5]
Output: True
Explanation:
You can split them into two consecutive subsequences :
1, 2, 3
3, 4, 5
``````

Example 2:

``````Input: [1,2,3,3,4,4,5,5]
Output: True
Explanation:
You can split them into two consecutive subsequences :
1, 2, 3, 4, 5
3, 4, 5
``````

Example 3:

``````Input: [1,2,3,4,4,5]
Output: False
``````

Note:

• The length of the input is in range of [1, 10000]

## # 解题方法

1，2，3，3，4，4，5，5

``````num	last	        len	    current	        map
1	null->(0,[ ])	0	    (1, [1])	(0,[ ] ) (1, [1])
2	(1, [1])	    1	    (2, [2])	(0,[ ] ) (1, [ ])(2, [2])
3	(2, [2])	    2	    (3, [3])	(0,[ ] ) (1, [ ])(2, [ ])(3, [3])
3	(2, [ ])	    0	    (3, [1])	(0,[ ] ) (1, [ ])(2, [ ])(3, [3])(3, [1])
4	(3, [1])	    1	    (4, [2])	(0,[ ] ) (1, [ ])(2, [ ])(3, [3])(3, [ ])(4, [2])
4	(3, [3])	    3	    (4, [4])	(0,[ ] ) (1, [ ])(2, [ ])(3, [ ])(3, [ ])(4, [2])(4, [4])
5	(4, [2])	    2	    (5, [3])	(0,[ ] ) (1, [ ])(2, [ ])(3, [ ])(3, [ ])(4, [ ])(4, [4])(5, [3])
5	(4, [4])	    4	    (5, [5])	(0,[ ] ) (1, [ ])(2, [ ])(3, [ ])(3, [ ])(4, [ ])(4, [ ])(5, [3])(5, [5])
``````

``````class Solution(object):
def isPossible(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
saved = collections.defaultdict(list)
for num in nums:
last = saved[num - 1]
_len = 0 if (not last) else heapq.heappop(last)
current = saved[num]
heapq.heappush(current, _len + 1)
for values in saved.values():
for v in values:
if v < 3:
return False
return True

``````

1. https://blog.csdn.net/sunday0904/article/details/78174122

## # 日期

2018 年 8 月 29 日 ———— 还是要早起才行啊！