Skip to content

Commit bed0c7e

Browse files
authored
Create divide-array-in-sets-of-k-consecutive-numbers.py
1 parent 289ac47 commit bed0c7e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Time: O(nlogn)
2+
# Space: O(n)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def isPossibleDivide(self, nums, k):
9+
"""
10+
:type nums: List[int]
11+
:type k: int
12+
:rtype: bool
13+
"""
14+
count = collections.Counter(nums)
15+
for num in sorted(count.keys()):
16+
c = count[num]
17+
if not c:
18+
continue
19+
for i in xrange(num, num+k):
20+
if count[i] < c:
21+
return False
22+
count[i] -= c
23+
return True

0 commit comments

Comments
 (0)